开发者

selection range issue in IE9

开发者 https://www.devze.com 2023-02-22 18:25 出处:网络
I have the following JavaScript code works in IE6, IE7 and IE8. However, the parentEleme开发者_运维知识库nt() and commonParentElement() are not defined in IE9. Would anyone know how to workaround it?

I have the following JavaScript code works in IE6, IE7 and IE8. However, the parentEleme开发者_运维知识库nt() and commonParentElement() are not defined in IE9. Would anyone know how to workaround it?

if (document.selection)
{
    var sel = document.selection; 
    var rng = sel.createRange();
    if (rng) 
    {
           if ("Control" == sel.type && typeof rng.commonParentElement != "undefined") 
           {
                targetElement = rng.commonParentElement(); // undefined in IE9
           }
           else if (typeof rng.parentElement != "undefined")
           {
                targetElement = rng.parentElement(); // undefined in IE9
           }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号