當前位置:吉日网官网 - 盛世收藏 - 在chrome瀏覽器下實現加入收藏夾的javascript代碼該咋寫?

在chrome瀏覽器下實現加入收藏夾的javascript代碼該咋寫?

添加到收藏夾這壹功能,不能覆蓋所有瀏覽器,所以這裏要采用漸進式增強的思想。

下面的寫法兼容了IE、Firefox、Opera。而在chrome下提醒用戶按快捷鍵收藏。

<a rel="sidebar" title="聯想導航" href="">添加收藏</a>

<script>

$("a[rel='sidebar']").click(function(e) {

var href = this.href || document.location,

title = this.title || document.title;

try{

if(window.sidebar){

sidebar.addPanel(title, href, "");

}else{

external.addFavorite(href, title);

}

}catch(e){

alert("加入收藏失敗,請按Ctrl+D進行添加");

}

return false;

});

</script>

  • 上一篇:四個美好的字,值得收藏。
  • 下一篇:坐高鐵可以帶5萬現金嗎?
  • copyright 2024吉日网官网