Small examples of JavaScript Settings for home and favorite pages

  • 2020-03-27 00:01:20
  • OfStack


<html> 
   <head> 
      <title>JavaScript Set home page and favorites page (compatible IE With firefox) </title> 
      <script> 
      //Url: links to be collected; Title: the name of the favorite item
      function AddFavorite(url,title) 
      { 
         //If the url or title is empty, the default is the current page url and title.
         if(!(url&&title)) 
         { 
            url=document.URL; 
            title=document.title;  
         } 

         if (document.all)//IE 
         { 
               window.external.addFavorite(url,title); 
         } 
         else if (window.sidebar)// firefox  
         { 
            window.sidebar.addPanel(title, url, ""); 
         } 
      } 

      //Url: the link to set to the home page
      function SetHomepage(url) 
      { 
         //If the url is empty, the default is the current page url.
         if(!url) 
         { 
            url=document.URL; 
         } 

         if (document.all)//IE  
         { 
            document.body.style.behavior = 'url(#default#homepage)'; 
            document.body.setHomePage(url); 
         } 
         else if (window.sidebar)// firefox  
         { 
            if (window.netscape) 
            { 
               try 
               { 
                  window.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
               } 
               catch (e) 
               { 
                  alert(" This operation was rejected by the browser! Please enter" about:config "And press enter and then will [signed.applets.codebase_principal_support] Is set to 'true', Just double click. "); 
               } 
            } 
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 
            prefs.setCharPref('browser.startup.homepage', url); 
         } 
      }  
      </script> 
   </head> 
   <body> 
      <a onClick="SetHomepage('//www.jb51.net/')" title=" set the home page "href="javascript:"> Set home </ a>
      <a onClick="AddFavorite('//'www.jb51.net/' and 'online note) "title =" collection "href =" javascript: "> Collect </ a>
   </body> 
</html> 

Related articles: