先说明一下,由于某些浏览器存在安全问题,设置主页和加入收藏夹不能全兼容,抛弃这功能吧~
<script type="text/javascript">
$(function () {
//加入收藏
$("#favorites").click(function () {
var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';
if (document.all) {
window.external.addFavorite(window.location, document.title);
}
else if (window.sidebar) {
window.sidebar.addPanel(document.title, window.location);
}
else {//添加收藏的快捷键
alert('添加失败\n您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~');
}
});
//设置主页
$("#addHomePage").click(function () {
if (document.all) {//设置IE
document.body.style.behavior = 'url(#default#homepage)';
document.body.setHomePage(document.URL);
}
else {//网上可以找到设置火狐主页的代码,但是点击取消的话会有Bug,因此建议手动设置
//alert("设置首页失败,请手动设置!");
try {
this.style.behavior = 'url(#default#homepage)';
this.setHomePage(document.URL);
} catch (e) {
if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("抱歉,此操作被浏览器拒绝!\n\n请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
}
} else {
alert("抱歉,您所使用的浏览器无法完成此操作。\n\n您需要手动将【" + document.URL + "】设置为首页。");
}
}
}
});
//回到顶部
$("#backToTop").click(function () { $('body,html').animate({ scrollTop: 0 }, 1000); return false; });
})
</script>