Greasemonkey:使用GM_xmlhttpRequest和createContextualFragment加载url

时间:2010-02-08 12:03:01

标签: greasemonkey

我有以下GreaseMonkey脚本:

GM_xmlhttpRequest({
     method: 'GET',
     url: "http://www.testurl.com",
     headers: {
         'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3',
     },
     onload: function(responseDetails) {

   var tagString = responseDetails.responseText;       
   var range = document.createRange();
   range.selectNode(document.body);
   var documentFragment = range.createContextualFragment(tagString);

我现在如何从documentFragment中提取内容? documentFragment.getElementById(''),document.body等都返回undefined。

我怀疑这是由于createContextualFragment方法返回一个XPCNativeWrapper对象,但是如何解决这个问题以访问底层DOM呢?

由于

2 个答案:

答案 0 :(得分:1)

不确定Load and parse remote url with greasemonkey

是否回答了这个问题

根据您的想法,可能更容易包含jquery ..

答案 1 :(得分:0)

  

我怀疑这是由于   createContextualFragment方法   返回一个XPCNativeWrapper对象,   但是我该如何解决这个问题呢   访问底层DOM?

这是使用wrappedJSObject

完成的
var documentFragment = range.createContextualFragment(tagString).wrappedJSObject;
相关问题