开发者

document.evaluate in chrome and firefox

开发者 https://www.devze.com 2023-03-13 07:22 出处:网络
I need help with this. I am new to using XPath in javascript and this one has stumped me. My script retrieves the contents of a web page using xmlhttp and then wraps it up in a \'div\':

I need help with this. I am new to using XPath in javascript and this one has stumped me.

My script retrieves the contents of a web page using xmlhttp and then wraps it up in a 'div':

            div=document.createElement('div');
            div.innerHTML=xmlhttp.responseText.replace(/<img[^>]*>/); 

I need to access the body content of this wrapped division and I am using Xpath to do this:

bodyContent = document.evaluate("//*[@id='bodyContent']", div ,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
bodyContent = bodyContent.snapshotItem(0);

While this works perfectly well in firefox and retrieves the required XpathObject it does not give the desired result for google chrome browser. Where instead of returning the bodyC开发者_开发技巧ontent division of the 'div' element created (and passed as contextNode) it returns the bodyContent of the current document page.

I have checked and in chrome -- the correct xmlhttp.reponseText is received.

Any ideas regarding this?

Thanks,


Does document.evaluate(".//*[@id='bodyContent']", div ,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null) give you the desired result in both browsers?

0

精彩评论

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