我的 iframe id="iView"和 designMode = on。
我的代码:
var iframeWindow = document.getElementById('iView').contentWindow.document;
var range = iframeWindow.getSelection().getRangeAt(0);
我得到的错误:
Microsoft JScript runtime error: Object doesn't support this property or method
我也试过
的答案
how to get selected text from iframe with javascript?
最佳答案
IE中没有document对象的getSelection方法,必须使用selection对象。
var selText;
var iframeWindow = document.getElementById('iView').contentWindow;
if (iframeWindow.getSelection)
selText = iframeWindow.getSelection()+"";
else if (iframeWindow.document.selection)
selText = iframeWindow.document.selection.createRange().text;
关于javascript - 在 IE 的 iframe 中获取选定的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1877138/