在IE中的iframe中获取所选文本 [英] Getting selected text within iframe in IE

查看:58
本文介绍了在IE中的iframe中获取所选文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iframe有id =iView而designMode = on。

I have iframe with id="iView" and designMode = on.

我的代码:

 var iframeWindow = document.getElementById('iView').contentWindow.document;                                                                                            
 var range = iframeWindow.getSelection().getRangeAt(0);

我得到的错误:


Microsoft JScript运行时错误:
对象不支持此属性
或方法

Microsoft JScript runtime error: Object doesn't support this property or method

我也尝试过来自
的答案如何使用javascript从iframe中获取所选文本?

推荐答案

IE中的文档对象没有getSelection方法,你必须改用选择对象。

There is no getSelection method for the document object in IE, you have to use the selection object instead.

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;

这篇关于在IE中的iframe中获取所选文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆