Bookmarking a page:
|
![]() |
Question: Can I bookmark a webpage programmatically from JavaScript?
Answer:
In Internet Explorer 4.0 and newer versions, you can invoke the browser's Add Favorite dialog
by calling the method window.external.AddFavorite()
.
In Firefox, similar functionality can be achieved using the method window.sidebar.addPanel()
.
Other major browsers do not support these methods. Still, your script can simply remind the users to create a bookmark by using the Bookmark menu item or keyboard shortcut (see example below).
Example:
In Internet Explorer, this script displays the Add Favorite dialog.
In Firefox, it displays the New Bookmark dialog.
In other browsers, the script
reminds the user to create
Try this now: click the button Bookmark JavaScript FAQ!
createBookmark
; here is the source code:
function createBookmark(sURL,sTitle) { if (document.all && window.external) { window.external.AddFavorite (sURL,sTitle); } else if (window.sidebar) { window.sidebar.addPanel(sTitle,sURL,''); } else { alert ('' +'Cannot programmatically add bookmarks!\n' +'Please press Ctrl+D to bookmark this page.' ); } }
See also other JavaScript dialogs:
Copyright © 1999-2011, JavaScripter.net.