This program is set to the homepage to automatically obtain the domain name of the current document URL, and the description added to the favorite is taken from the title of the current document.
Code:
program code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns=" http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Set as homepage--Add to favorites</title>
<script type="text/javascript">
function setHomePage(obj){
var aUrls=document.URL.split("/");
var vDomainName=" http://"+aUrls[2]+"/ ";
try{//IE
obj.style.behavior="url(#default#homepage)";
obj.setHomePage(vDomainName);
}catch(e){//other
if(window.netscape) {//ff
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {
alert("This operation is rejected by the browser!nPlease enter "about:config" in the browser address bar and press EnternThen set [signed.applets.codebase_principal_support] to 'true'");
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage',vDomainName);
}
}
if(window.netscape)alert("ff");
}
function addFavorite(){
var aUrls=document.URL.split("/");
var vDomainName=" http://"+aUrls[2]+"/ ";
var description=document.title;
try{//IE
window.external.AddFavorite(vDomainName,description);
}catch(e){//FF
window.sidebar.addPanel(description,vDomainName,"");
}
}
</script>
</head>
<body>
<input type="button" value="Set as homepage" onclick="setHomePage(this);" /> <input type="button" value="Add to favorites" onclick="addFavorite();" />
</body>
</html>