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);
精彩评论