bookmarks, Javascript and your web browser

Unfortunately, the process of bookmarking a page automatically using Javascript is not consistent between browsers and some do not support it at all. To my knowledge only Firefox (and derivatives), Opera and IE currently allow a bookmark to be added via Javascript though this could change at any time. If you are reading this page you either are trying to learn how to add a bookmark or you came here by accident because your browser is unsupported or you have Javascript turned off (if the latter reason reflects your situation, good for you). Keep in mind you can always manually add a bookmark using your browser's menu options.

how to add a bookmark using Javascript

The following code will add trigger addition of a bookmark for Firefox, Opera and IE. For all other browsers (assuming they have Javascript turned on), an alert will be raised letting the user know to manually add the link themselves.

If anyone knows a way to add a bookmark with any browsers not covered here (Safari, Google Chrome, etc.), please let me know so I can update this code.

function add_bookmark(url,page_title) { if(window.sidebar) // Firefox / Mozilla { window.sidebar.addPanel(page_title, url,''); } else if(window.opera) // Opera { var a = document.createElement('A'); a.rel = 'sidebar'; a.target = '_search'; a.title = page_title; a.href = url; a.click(); } else if(window.external) // Inept Exploiter { window.external.AddFavorite(url, page_title); } else { alert(' Your web browser appears to not support adding a bookmark via Javascript. Please manually add one via your browser's bookmark menu. '); } }

There you have it, a simple Javascript function to add a bookmark in the more common web browsers.

CODEgrunt consulting

Experienced PHP web developer.

$35 an hour, no job too small.

There is no replacement for integrity and experience.

Contact me for more information.

calendar

February 2012

Sun
Mon
Tue
Wed
Thu
Fri
Sat
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
1
2
3