Dom IE9中的选择范围问题

Dom IE9中的选择范围问题,dom,selection,range,internet-explorer-9,Dom,Selection,Range,Internet Explorer 9,我在IE6、IE7和IE8中使用了以下JavaScript代码。但是,IE9中没有定义parentElement()和commonParentElement()。有人知道如何解决这个问题吗 if (document.selection) { var sel = document.selection; var rng = sel.createRange(); if (rng) { if ("Control" == sel.type &

我在IE6、IE7和IE8中使用了以下JavaScript代码。但是,IE9中没有定义parentElement()和commonParentElement()。有人知道如何解决这个问题吗

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
           }
    }
}

似乎相关。我强烈建议在ie9+中使用基于标准的范围对象(与所有其他浏览器中使用的相同)。它的bug要少得多。