在Javascript中创建“添加到收藏夹/书签”按钮
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Javascript中创建“添加到收藏夹/书签”按钮相关的知识,希望对你有一定的参考价值。
Most today's web browsers like Firefox (Ctrl+D), Opera (Ctrl+T) and IE (Ctrl+D) provide a keyboard shortcuts to enable users bookmark their favorite pages. But if you want to provide your visitors with a "Bookmark this page" link they can click you may use the code below: It works in IE, FireFox and Opera. Clicking on the link prompts the user with a dialog box to add the specified URL to the Favorites list.
function CreateBookmarkLink(){ var title = document.title; var url = document.location.href; if(window.sidebar){ /* Mozilla Firefox Bookmark */ window.sidebar.addPanel(title, url, ""); }else if(window.external){ /* IE Favorite */ window.external.AddFavorite(url, title); }else if(window.opera && window.print) { /* Opera Hotlist */ alert("Press Control + D to bookmark"); return true; }else{ /* Other */ alert("Press Control + D to bookmark"); } } </script> <a href="javascript:CreateBookmarkLink();">Add to Favorites/Bookmark</a>
以上是关于在Javascript中创建“添加到收藏夹/书签”按钮的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript 在JavaScript中创建一个空对象