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