在Chrome浏览器和铬中不支持Discontigious Selection错误 [英] Discontigious Selection is not supported error in google chrome and chromium

查看:186
本文介绍了在Chrome浏览器和铬中不支持Discontigious Selection错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个书签应用程序,我必须存储用户选择的关键字或单词或内容。我使用createRange()和addRange()javascript方法来创建范围,然后找出用户选定的元素/内容。我为此编写的代码如下。

 < head> 
< script type =text / javascript>
var storedSelections = [];

函数StoreSelection(){
if(window.getSelection){
var currSelection = window.getSelection(); (var i = 0; i< currSelection.rangeCount; i ++){
storedSelections.push(currSelection.getRangeAt(i))的
;
}
currSelection.removeAllRanges();
} else {
alert(你的浏览器不支持这个例子!



函数ClearStoredSelections(){
storedSelections.splice(0,storedSelections.length);


函数ShowStoredSelections(){
if(window.getSelection){
var currSelection = window.getSelection();
currSelection.removeAllRanges();
for(var i = 0; i< storedSelections.length; i ++){
currSelection.addRange(storedSelections [i]);

} else {
alert(你的浏览器不支持这个例子!
}
}
< / script>
< / head>
< body>
在此页面上选择一些内容并使用下面的按钮。< br /> < br />
< button onclick =StoreSelection();>存储选择< /按钮>
< button onclick =ClearStoredSelections();>清除存储的选择
< / button>
< button onclick =ShowStoredSelections();>显示存储的选择< /按钮>

< / body>

这段代码在Firefox上完美运行。我能够一个一个地选择多件事物,并且能够再次显示所选内容,但是在铬和铬上我得到了不支持不连续的选择。​​当我存储更多比范围数组中的一个元素,然后单击显示存储选择按钮。



帮助将不胜感激。如果还有其他一些替代品可以完成这个书签任务,请给我建议。

解决方案

  window.getSelection()removeAllRanges(); 

紧接在创建范围之前。

< a href =https://bugs.chromium.org/p/chromium/issues/detail?id=399791 =noreferrer> https://bugs.chromium.org/p/chromium/issues/detail? id = 399791


I am working on a bookmark app where i have to store the user's selected keywords or words or content. I am using the createRange() and addRange() javascript methods to create the range and then find out the selected elements/contents by the user. The code i written for this is as follow.

<head>
<script type="text/javascript">
    var storedSelections = [];

    function StoreSelection () {
        if (window.getSelection) {
            var currSelection = window.getSelection ();
            for (var i = 0; i < currSelection.rangeCount; i++) {
                storedSelections.push (currSelection.getRangeAt (i));
            }
            currSelection.removeAllRanges ();
        } else {
            alert ("Your browser does not support this example!");
        }
    }

    function ClearStoredSelections () {
        storedSelections.splice (0, storedSelections.length);
    }

    function ShowStoredSelections () {
        if (window.getSelection) {
            var currSelection = window.getSelection ();
            currSelection.removeAllRanges ();
            for (var i = 0; i < storedSelections.length; i++) {
                currSelection.addRange (storedSelections[i]);
            }
        } else {
            alert ("Your browser does not support this example!");
        }
    }
</script>
</head>
<body>
    Select some content on this page and use the buttons below.<br />         <br />
    <button onclick="StoreSelection ();">Store the selection</button>
    <button onclick="ClearStoredSelections ();">Clear stored selections
</button>
    <button onclick="ShowStoredSelections ();">Show stored selections</button>

</body>

This code is working perfectly on Firefox. I am able to select multiple things one by one and able to show the selected content again but on chrome and chromium i am getting Discontiguous selection is not supported. error when i store more than one elements in range array and click on show stored selections button.

Help will be appreciated. And please suggest me if there is some other alternatives do accomplish this bookmarking task.

解决方案

Write

window.getSelection().removeAllRanges();

immediately before creating range.

https://bugs.chromium.org/p/chromium/issues/detail?id=399791

这篇关于在Chrome浏览器和铬中不支持Discontigious Selection错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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