代码:
function addFavorite(el){var url = window.location.href,title = $('head').find('title').html();try{//IEwindow.external.AddFavorite(url, title);}catch(e){ //Firefoxtry{window.sidebar.addPanel(title,url,'');}catch(e){if(window.opera){ //operael.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>