【问题标题】:Is there any way to track selection range in iframe's designMode?有没有办法在 iframe 的 designMode 中跟踪选择范围?
【发布时间】:2010-10-08 15:48:45
【问题描述】:

我已经对此进行了一段时间的试验,但没有得到任何效果 - 有没有办法在 iframe 的 designMode 中跟踪 mouseup 和选择,最好是在跨浏览器兼容模式下?

【问题讨论】:

    标签: javascript html dom cross-browser


    【解决方案1】:

    这是我在here 找到的一小段代码,希望对您有所帮助:

    function setRange(rte) {
        //function to store range of current selection
        var oRTE;
        if (document.all) {
            oRTE = frames[rte];
            var selection = oRTE.document.selection;
            if (selection != null) rng = selection.createRange();
        } else {
            oRTE = document.getElementById(rte).contentWindow;
            var selection = oRTE.getSelection();
            rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
        }
        return rng;
    }
    

    似乎您可以在文档对象上使用selection 属性,然后使用createRange() 方法。 if-else 可能用于跨浏览器支持。

    【讨论】:

      【解决方案2】:

      这是来自 Quirksmode 的出色 Introduction to Range。安全地跨浏览器获取文本选择的精彩概述。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-14
        • 1970-01-01
        相关资源
        最近更新 更多