I found a Javascript which is for adding bookmark to browser. Since Chrome and Safari do not support adding bookmark by Javascript, an alert box will be prompted and tell the user using Ctrl + D to add the bookmark instead.
<html> <head> <title>Eureka! - add to bookmark</title> <script type="text/javascript"> /** * Copyright 2010 by GlamThumbs Team. * * This is an example to demostrate the BookmarkApp.js by GlamThumbs Team. * Reference: http://glamthumbs.com/BookmarkApp.js * Reference: http://stackoverflow.com/questions/992844/add-to-browser-favorites-bookmarks-from-javascript-but-for-all-browsers-mine-doe * */ BookmarkApp = function () { var isIEmac = false; /*@cc_on @if(@_jscript&&!(@_win32||@_win16)&&(@_jscript_version<5.5)) isIEmac=true; @end @*/ var isMSIE = (-[1,]) ? false : true; var cjTitle = document.title; // Bookmark title var cjHref = location.href; // Bookmark url function hotKeys() { var ua = navigator.userAgent.toLowerCase(); var str = ''; var isWebkit = (ua.indexOf('webkit') != - 1); var isMac = (ua.indexOf('mac') != - 1); if (ua.indexOf('konqueror') != - 1) { str = 'CTRL + B'; // Konqueror } else if (window.home || isWebkit || isIEmac || isMac) { str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab, IE5/Mac } return ((str) ? 'Press ' + str + ' to bookmark this page.' : str); } function isIE8() { var rv = -1; if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) { rv = parseFloat(RegExp.$1); } } if (rv > - 1) { if (rv >= 8.0) { return true; } } return false; } function addBookmark(a) { try { if (typeof a == "object" && a.tagName.toLowerCase() == "a") { a.style.cursor = 'pointer'; if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) { window.sidebar.addPanel(cjTitle, cjHref, ""); // Gecko return false; } else if (isMSIE && typeof window.external == "object") { if (isIE8()) { window.external.AddToFavoritesBar(cjHref, cjTitle); // IE 8 } else { window.external.AddFavorite(cjHref, cjTitle); // IE <=7 } return false; } else if (window.opera) { a.href = cjHref; a.title = cjTitle; a.rel = 'sidebar'; // Opera 7+ return true; } else { alert(hotKeys()); } } else { throw "Error occured.\r\nNote, only A tagname is allowed!"; } } catch (err) { alert(err); } } return { addBookmark : addBookmark } }(); </script> </head> <body> <p><a href="javascript:void(0)" onClick="return BookmarkApp.addBookmark(this)">bookmark me</a></p> </body> <html>
Done =)
Update @ 2013-04-13: Solution for IE suggested by Webmaster.
Thank you very much!
LikeLike
you are welcome =)
LikeLike
I get an error with IE9!
LikeLike
thanks for pointing out the issue. i will check if there is any workaround for ie9.
LikeLike
Is not working in IE9 :((
Please leave a comment about how we can fix the error
LikeLike
T test in my website http://handmaderetail.com/ the code ant is not working in IE9 :((
LikeLike
Unfortunately there is no a generic solution which works across all browsers. i find another post about the same issue as u, hope u can get some idea from it.
StackOverflow – How can I use JS to add a bookmark specifically in IE9
LikeLike
Nice! Here’s the quick fix for IE. Change:
to:
LikeLike
Thanks for your solution. =D
LikeLike