[转载]【jquery】收藏本站——添加到浏览器的收藏夹 – 朱羽佳 – 博客园.
基本上兼容了所有的浏览器,值得收藏。
直接上代码:
<!DOCTYPE HTML> <html lang= "en-US" > <head> <meta charset= "UTF-8" > <title>收藏本站</title> </head> <body> <a href= "javascript:;" title= "收藏本站" id= "fav" >收藏本站</a> </body> </html> <script type= "text/javascript" src= "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.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( '收藏本站' ,location.href); }); </script> |