Saturday, May 25, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  151] [ 2]  / answers: 1 / hits: 16371  / 13 Years ago, mon, january 2, 2012, 12:00:00

Is it possible to download the entire HTML of a webpage using JavaScript given the URL? What I want to do is to develop a Firefox add-on to download the content of all the links found in the source of current page of browser.



update: the URLs reside in the same domain


More From » html

 Answers
37

It should be possible to do using jQuery ajax. Javascript in a Firefox extension is not subject to the cross-origin restriction. Here are some tips for using jQuery in a Firefox extension:




  1. Add the jQuery library to your extension's chrome/content/ directory.


  2. Load jQuery in the window load event callback rather than including it in your browser overlay XUL. Otherwise it can cause conflicts (e.g. clobbers a user's customized toolbar).



    (function(loader){ 
    loader.loadSubScript(chrome://ryebox/content/jquery-1.6.2.min.js); })
    (Components.classes[@mozilla.org/moz/jssubscript-loader;1].getService(Components.interfaces.mozIJSSubScriptLoader));

  3. Use jQuery instead of $. I experienced weird behavior when using $ instead of jQuery (a conflict of some kind I suppose)


  4. Use jQuery(content.document) instead of jQuery(document) to access a page's DOM. In a Firefox extension document refers to the browser's XUL whereas content.document refers to the page's DOM.




I wrote a Firefox extension for getting bookmarks from my friend's bookmark site. It uses jQuery to fetch my bookmarks in a JSON response from his service, then creates a menu of those bookmarks so that I can easily access them. You can browse the source at https://github.com/erturne/ryebox


[#88276] Saturday, December 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elliem

Total Points: 415
Total Questions: 117
Total Answers: 94

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
;