目前兼容IE系列和Firefox,至于其他的浏览器,则弹窗提示“用Ctrl+D来加入收藏”。看代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<script type="text/javascript">
// 天涯PHP博客 http://blog.phpha.com
function bookmark(title, url) {
if(document.all) { // ie
window.external.AddFavorite(url, title);
}else if(window.sidebar) { // firefox
window.sidebar.addPanel(title, url, "");
}else if(window.opera && window.print) { // opera
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click(); // this.title=document.title;
}else{
alert("加入收藏失败,请使用Ctrl+D进行添加");
}
}
</script>
至于设为首页,貌似目前只有针对IE系列的唯一解决方案,代码如下:
1
2
<a href="javascript:;" onclick="bookmark('天涯PHP博客', 'http://blog.phpha.com');">加入收藏</a>
<a href="javascript:;" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://blog.phpha.com');">设为首页</a>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。