function setHomepage()
{
var url = window.location.href;
if (document.all)
{
document.body.style.behavior=‘url(#default#homepage)‘;
document.body.setHomePage(url);
}
else if (window.sidebar)
{
if(window.netscape)
{
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e)
{
alert( "设为首页操作被浏览器拒绝,如果想启用设为首页功能,请选择信任此代码" );
}
}
var prefs = Components.classes[‘@mozilla.org/preferences-service;1‘].getService(Components. interfaces.nsIPrefBranch);
prefs.setCharPref(‘browser.startup.homepage‘,url);
}
}