iframeElm.contentWindow.document.selection不适用于< iframe>在IE中,如果在iframe中进行选择后将焦点设置在其他输入上 [英] iframeElm.contentWindow.document.selection not working for <iframe> in IE if set focus on other input after making selection in the iframe

查看:231
本文介绍了iframeElm.contentWindow.document.selection不适用于< iframe>在IE中,如果在iframe中进行选择后将焦点设置在其他输入上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于如何在选择iframe的可编辑内容时设置html的类似但不同的问题。

This is similar but different question about how to set html in the selection of the iframe's editable content.

找到的一个示例是: http://jsfiddle.net/HMRMv/1/ ,但它也可用于显示问题。

One sample found is: http://jsfiddle.net/HMRMv/1/, but it can also be used to show the problem.

在IE上,如果你在iframe中选择文本然后点击它,它会起作用。
但是在选择iframe可编辑内容中的文本而不是单击其他窗格后,您将看到突出显示消失,按钮上的单击将不执行任何操作。看起来像:

On IE, in the sample if you select the text in iframe and then do the click, it will work. But after select the text in the iframe's editable content and than clicking on other pane, you will see the highlight disappear and the 'click' on the button will do nothing. Look like the:

var range = document.getElementById("iframe").contentWindow.document.selection.createRange(); 

无法获得之前选择的范围。

Cannot get the previous selected range.

我尝试在模糊中缓存范围并在点击时重复使用它,但它不起作用。是否与iframe有关,对此案例有何建议?

I tried cache the range in blur and reuse it at the 'click', but it does not work. Is it to do with iframe, any suggestion on this case?

var selectedType, selectedRange;

function onBlur(e) {
    var selection = iframeElm.contentWindow.document.selection;
    var range = selection.createRange();

    selectedType= selection.type;
    selectedRange = range;
}


推荐答案

blur 事件为时已晚,无法缓存选择范围,因为此时选择已被破坏。使用仅限IE的 之前在iframe元素上激活 事件。

The blur event is too late to cache the selection range because the selection is already destroyed by then. Use the IE-only beforedeactivate event on the iframe element instead.

演示: http://jsfiddle.net/HMRMv/34/

这篇关于iframeElm.contentWindow.document.selection不适用于< iframe>在IE中,如果在iframe中进行选择后将焦点设置在其他输入上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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