<!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=utf-8" />
<title>兼容ie,chrome,ff的设为首页和收藏本站js代码 web前端资源网 | www.tonjay.com</title>
</head>
<body>
<script type="text/javascript">
function AddFavorite(sURL, sTitle) {
try { //IE
window.external.addFavorite(sURL, sTitle);
} catch (e) {
try { //Firefox
window.sidebar.addPanel(sTitle, sURL, "");
} catch (e) {
try{//Chrome无法自动收藏,用创建快应用程序的捷方式来替代。web前端资源网 www.tonjay.com
createShortcut();
} catch(e){
alert("请按Ctrl+D之后按“确定”完成收藏!");
}
}
}
}
function setHomepage(pageURL) {
if (document.all) {
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(pageURL);
}
else {
try { //IE
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
try{ //Firefox
var prefs = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components. interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage',pageURL);
} catch(e) {
alert( "您的浏览器不支持该操作,请使用浏览器菜单手动设置." );
}
}
}
}
</script>
<style>
p a{ margin:0 20px; text-decoration:none; color:#666;}
p a:hover{ color:#000;}
</style>
<p align="center">
<a href="javascript:void(0);" title="加入收藏" onclick="setHomepage('http://www.tonjay.com');">设为首页</a>
<a href="javascript:void(0)" title="加入收藏" onclick="javascript:AddFavorite('http://www.tonjay.com','web前端资源网');">加入收藏</a></p>
</body>
</html>