Native js written, compatible with ie, firefox and Google.
Complete code:
<script type="text/javascript">//Set as homepage www.VeVB.COMfunction SetHome(obj,url){ try{ obj.style.behavior='url(#default#homepage)'; obj.setHomePage(url); }catch(e){ if(window.netscape){ try{ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); }catch(e){ alert("Sorry, this operation was rejected by the browser! /n/nPlease enter "about:config" in the browser address bar and press Enter and set [signed.applets.codebase_principal_support] to 'true'"); } }else{ alert("Sorry, the browser you are using cannot complete this operation. /n/nYou need to manually set ["+url+"] to homepage."); } }} //Save this site www.VeVB.COMfunction AddFavorite(title, url) { try { window.external.addFavorite(url, title); }catch (e) { try { window.sidebar.addPanel(title, url, ""); } catch (e) { alert("Sorry, the browser you are using cannot complete this operation. /n/n failed to add to favorites. Please use Ctrl+D to add it"); } }}</script><a href="javascript:void(0);" onclick="SetHome(this,'//www.VeVB.COM');">Set as homepage</a><div><a href="javascript:void(0);" onclick="AddFavorite('Wulin.com','//www.VeVB.COM')">Save this site</a>The following can be referenced:
The function is as follows:
The code copy is as follows:
function setHome(obj,url){
try{
obj.style.behavior = 'url(#default#homepage)';
obj.setHomePage(url);
}catch(e){
if(window.netscape){
try{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
}catch(e){
alert('Sorry, this operation was rejected by the browser! /n/n Please enter "about:config" in the browser address bar and press /n/n and then set the value of [signed.applets.codebase_principal_support] to true, and double-click.');
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage',url);
}else{
alert('Sorry, the browser you are using cannot do this. /n/n You need to manually set [' + url + '] to the homepage.');
}
}
}
How to use:
The code copy is as follows:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Set as homepage</title>
</head>
<body>
<a href="javascript:;" onclick="setHome(this,window.location);">Set as homepage</a>
</body>
</html>