tags:

views:

252

answers:

2

I have the following GreaseMonkey Script:

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);

How do I now extract stuff from documentFragment? documentFragment.getElementById(''), document.body etc all returns undefined.

I suspect this is due to the createContextualFragment method returning a XPCNativeWrapper object, but how do I work around this to access the underlying DOM?

Thanks

+1  A: 

Not sure if this is answered by http://stackoverflow.com/questions/2211430/load-and-parse-remote-url-with-greasemonkey

Depending what you want to do, might be easier to include jquery..

aland
haha, only just noticed that was another of your questions :D
aland
A: 

I suspect this is due to the createContextualFragment method returning a XPCNativeWrapper object, but how do I work around this to access the underlying DOM?

This is done using wrappedJSObject:

var documentFragment = range.createContextualFragment(tagString).wrappedJSObject;
hlovdal