JavaScript收藏功能實現
<!DOCTYPE html> <html> <head> <title>demo</title> <meta charset="utf-8"> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <script type="text/javascript"> jQuery.fn.addFavorite = function(l, h) { return this.click(function() { var t = jQuery(this); if(jQuery.browser.msie) { window.external.addFavorite(h, l); } else if (jQuery.browser.mozilla || jQuery.browser.opera) { t.attr("rel", "sidebar"); t.attr("title", l); t.attr("href", h); } else { alert("請使用Ctrl+D將本頁加入收藏夾!"); } }); }; $(function(){ $('#fav').addFavorite(document.title,location.href); }); </script> </head> <body> <a href="javascript:;" title="收藏本站" id="fav">收藏本站</a> </body> </html>
本文由用戶 jsopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!