开发者

Bookmark page using JavaScript

window.location.href does not work to sav开发者_运维知识库e the current web page url as a bookmark. Does anyone perhaps know why?

Thanks


This code works in Firefox as well as 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>


Use this code instead...

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜