使用JavaScript书签页面

时间:2011-02-21 10:17:18

标签: javascript

window.location.href无法将当前网页网址另存为书签。有谁也许知道为什么?

由于

2 个答案:

答案 0 :(得分:1)

请改用此代码......

javascript:window.external.AddFavorite(location.href, document.title);

答案 1 :(得分:1)

此代码适用于Firefox和IE。

function CreateBookmarkLink() {

 title = "Webpage Title"; 
 //or title = document.title

 url = "Webpage URL";
 //or url = location.href

if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
} else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title); }

}

Source

<a href="javascript:CreateBookmarkLink()" >Bookmark Page</a>