Javascript 如何获得iFrame的选择?

Javascript 如何获得iFrame的选择?,javascript,google-chrome,iframe,getselection,Javascript,Google Chrome,Iframe,Getselection,如果至少使用chrome浏览器查看,则以下代码会使用当前页面上选择的文本警告消息: alert(window.getSelection()); 但是,即使所选内容是iFrame中的文本,我如何才能让它工作呢?(iFrame内容属于同一个域)这应该可以: document.getElementById('iframe_id').contentWindow.getSelection(); 谢谢你!实际上,在Chrome中,您似乎想使用…contentDocument.getSelection()

如果至少使用chrome浏览器查看,则以下代码会使用当前页面上选择的文本警告消息:

alert(window.getSelection());
但是,即使所选内容是iFrame中的文本,我如何才能让它工作呢?(iFrame内容属于同一个域)

这应该可以:

document.getElementById('iframe_id').contentWindow.getSelection();

谢谢你!实际上,在Chrome中,您似乎想使用…contentDocument.getSelection()来代替。