home *** CD-ROM | disk | FTP | other *** search
/ PC World 2006 December / PCWorld_2006-12_cd.bin / komunikace / netscape / nsb-install-8-1-2.exe / chrome / browser.jar / content / browser / homeButton.js < prev    next >
Text File  |  2006-01-06  |  2KB  |  75 lines

  1.  
  2.  
  3. function homeButtonSetHomePageToCurrentPage()
  4. {
  5.   dump("\nhomeButtonSetHomePageToCurrentPage function called...\n\n");
  6.   var rv;
  7.   var url = "";
  8.   var browser = this.document.getElementById("content");
  9.   url = browser.currentURI.spec;
  10.  
  11.   var prefs = Components.classes["@mozilla.org/preferences-service;1"].
  12.             getService(Components.interfaces.nsIPrefBranch);
  13.  
  14.   rv = prefs.setCharPref("browser.startup.homepage", url);
  15.  
  16.   rv = prefs.savePrefFile(null);
  17.   dump("\nPreferences written to file\n");
  18. }
  19.  
  20. function homeButtonSetHomePageToBookmark()
  21. {
  22.   dump("\homeButtonSetHomePageToBookmark function called...\n\n");
  23.     
  24.   var rv = { url: null };
  25.   openDialog("chrome://browser/content/bookmarks/selectBookmark.xul", "",
  26.              "centerscreen,chrome,modal=yes,dialog=yes,resizable=yes", rv);
  27.   if (rv.url) {
  28.     dump("\nsetting home page to " + rv.url + "\n");
  29.     var prefs = Components.classes["@mozilla.org/preferences-service;1"].
  30.               getService(Components.interfaces.nsIPrefBranch);
  31.  
  32.     rv = prefs.setCharPref("browser.startup.homepage", rv.url);
  33.  
  34.     rv = prefs.savePrefFile(null);
  35.     dump("\nPreferences written to file\n");
  36.   }
  37. }
  38.  
  39. function homeButtonSetHomePageToBlank(){
  40.   dump("\homeButtonSetHomePageToBlank function called...\n\n");
  41.   var url = "about:blank";
  42.   dump("\nsetting home page to " + url + "\n");
  43.   var prefs = Components.classes["@mozilla.org/preferences-service;1"].
  44.             getService(Components.interfaces.nsIPrefBranch);
  45.  
  46.   rv = prefs.setCharPref("browser.startup.homepage", url);
  47.  
  48.   rv = prefs.savePrefFile(null);
  49.   dump("\nPreferences written to file\n");
  50. }
  51.  
  52. //the Options dialog box sets it's own preferences, therefore this function is only intended
  53. //to be called from the main chrome area.
  54. function homeButtonSetHomePageToCurrentTabs()
  55. {
  56.   dump("\homeButtonSetHomePageToCurrentTabs function called...\n\n");    
  57.   var rv;
  58.   var newHomePage = "";
  59.   var browser;
  60.  
  61.   browser = this.document.getElementById("content");
  62.   var l = browser.mPanelContainer.childNodes.length; //number of currently open tabs
  63.  
  64.   for (var i = 0; i < l; i++) {
  65.     if (i) {
  66.       newHomePage += "|";
  67.     }
  68.     newHomePage += browser.getBrowserAtIndex(i).webNavigation.currentURI.spec;
  69.   }
  70.   var prefs = Components.classes["@mozilla.org/preferences-service;1"].
  71.             getService(Components.interfaces.nsIPrefBranch);
  72.   rv = prefs.setCharPref("browser.startup.homepage", newHomePage);
  73.   rv = prefs.savePrefFile(null);
  74. }
  75.