IE 8 getSelection().anchorOffset alternative

僤鯓⒐⒋嵵緔 提交于 2019-12-02 09:16:56

There is a solution. It is possible to extend browser's object model using Rangy library:

window.getSelection = rangy.getSelection

As it may take some time for Rangy to init and as we will not need this for modern browsers, some more workaround:

/* 
IE 8 getSelection() missing object and properties simple hack
*/
if (window.getSelection == undefined) {                /* IE? */
    var wgS = setInterval(function(){                  /* wait for Rangy */
        if (rangy.initialized) {
            window.getSelection = rangy.getSelection;  /* do the stuff */
            clearTimeout(wgS);                         /* exit */
        }
     }, 10);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!