javascript - 在 IE 的 iframe 中获取选定的文本

标签 javascript

我的 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/

相关文章:

javascript - 如何使用 HTML5 刮刮卡渲染随机背景

javascript - 如何配置 [mode] ="' sql'"在 Angular 7 中使用 ng2-ace-editor?

javascript - 强制浏览器重新加载缓存而不使用服务器端代码

javascript - 使用 NVM 的 Phusion Passenger 和 Rails 应用找不到 JavaScript 运行时

javascript - 使用scale属性调整svg元素的大小

javascript - 在 JavaScript 中将 "9:00 pm"转换为 "21:00:00"的正确方法是什么?

javascript - Firebase 3 - ref.getAuth() 等效

javascript - 如何通过Puppeteer的exposeFunction使用date.js?

javascript - Google 图表 - 能否将柱形图中的柱与图表的中心对齐?

javascript - 具有固定纵横比 div 的居中图像的 Flexslider 幻灯片