Skip to content Skip to sidebar Skip to footer

How To Extract/retrieve Source Code Given Url In Firefox Extention

I'm writing a Firefox extension that will analyze / parse the linked pages while the user is still on the current page. I know there are ways to retrieve the source code for the pa

Solution 1:

Maybe the following JavaScript snippet will help you:

var req = new XMLHttpRequest();
req.open("GET", linkedPageUrl, false);
req.send(null);
DoSomethingWithGivenSource(req.responseText);

This works synchronously. So after req.send(null) is executed, req.responseText contains the page source code. Generally it is recommended to avoid synchronous network actions however so a better approach would be to use an asynchronous request and add a callback for the load event:

var req = newXMLHttpRequest();
req.open("GET", linkedPageUrl, true);
req.addEventListener("load", function()
{
  DoSomethingWithGivenSource(req.responseText);
}, false);
req.send(null);

Post a Comment for "How To Extract/retrieve Source Code Given Url In Firefox Extention"