How can I turn a string of HTML into a DOM object in a Firefox extension?

I'm downloading a web page (tag soup HTML) with XMLHttpRequest and I want to take the output and turn it into a DOM object that I can then run XPATH queries on. How do I convert from a string into DOM object? It appears that the general solution is to create a hidden iframe and throw the contents of the string into that. There has been [talk][1] of updating [DOMParser][2] to support text/html but as of Firefox 3.0.1 you still get an `NS_ERROR_NOT_IMPLEMENTED` if you try. Is there any option besides using the hidden iframe trick? And if not, what is the best way to do the iframe trick so that your code works outside the context of any currently open tabs (so that closing tabs won't screw up the code, etc)? This is an example of why I'm looking for a solution other than the iframe hack, if I have to write *all* that code to have a robust solution, then I'd rather keep looking for something else. [1]: http://starkravingfinkle.org/blog/2007/03/how-to-parse-html-in-mozilla/ [2]: http://developer.mozilla.org/en/docs/DOMParser

以上就是How can I turn a string of HTML into a DOM object in a Firefox extension?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏