js实现IE/Firefox的收藏功能
代码:
function addFavorite(el){ var url = window.location.href, title = $('head').find('title').html(); try{//IE window.external.AddFavorite(url, title); }catch(e){ //Firefox try{ window.sidebar.addPanel(title,url,''); }catch(e){ if(window.opera){ //opera el.href = url; el.title = title; el.rel = 'sidebar'; }else{ alert('Sorry, your browser does not support this action, please bookmark this page manually by pressing Ctrl + D on PC or Cmd + D on Mac.'); } } } }
支持IE、Firefox和opera。
调用方法:
<a href="javascript:addFavorite(this);">收藏</a>