JavaScript Set Homepage | Add to Favorites JS code

Source: Internet
Author: User

We introduce a compatible all browsers to add to the collection code code, the approximate principle is that we based on the acquisition of user navigator.userAgent.toLowerCase () information to determine the browser, depending on whether the browser support to add the bookmark JS command, If you can automatically collect otherwise you will be prompted Ctrl+d manual collection.

1 functionAddFavorite2 () {2     varURL =window.location;3     vartitle =Document.title;4     varUA =navigator.userAgent.toLowerCase ();5     if(Ua.indexof ("360SE") >-1) {6Alert ("Due to the 360 browser feature limit, please press CTRL+D manual collection!") ");7     }8     Else if(Ua.indexof ("MSIE 8") >-1) {9Window.external.AddToFavoritesBar (URL, title);//IE8Ten     } One     Else if(document.all) { A   Try{ - window.external.addFavorite (URL, title); -}Catch(e) { theAlert (' Your browser does not support, please press CTRL+D manual collection! ')); -   } -     } -     Else if(Window.sidebar) { +Window.sidebar.addPanel (title, URL, "")); -     } +     Else { AAlert (' Your browser does not support, please press CTRL+D manual collection! ')); at     } -}

Copy this page code to save the JS file, and then in the place to be collected add

<hrefonclick= "Javascript:addfavorite2 ()"> Add to Favorites </a>
If the <a> does not add rel= "sidebar", then the error will be: Window.sidebar.addPanel is not a functionSet as homepage
functionSethome (OBJ,VRL) {Try{Obj.style.behavior= ' url (#default #homepage) '; Obj.sethomepage (VRL); }        Catch(e) {if(window.netscape) {Try{Netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect"); }                         Catch(e) {alert ("This action was rejected by the browser!" \ n Please enter "About:config" in the browser address bar and return to \ n and set [Signed.applets.codebase_principal_support] to ' true '); }                        varPrefs = components.classes[' @mozilla. Org/preferences-service;1 '].getservice (Components.interfaces.nsIPrefBranch); Prefs.setcharpref (' Browser.startup.homepage ', VRL); }        }    }
<onclick= "Sethome (this,window.location)"  style= "Cursor:hand"  > Set homepage </a>

JavaScript Set Homepage | Add to Favorites JS code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.