Custom Search
Logiclabz
  • Home
  • Javascript
  • Javascript function for Add to Favorites IE|Add to Bookmarks Mozilla Firefox/Opera 7+

Javascript function for Add to Favorites IE|Add to Bookmarks Mozilla Firefox/Opera 7+

Javascript function to implement add to favorites/bookmark in Internet Explorer, Mozilla Firefox and Opera 7+.

The below "AddToFavorites()" function can be used to anchor tag to implement Add to favorites/bookmark in Internet Explorer, Mozilla Firefox and Opera.

function AddToFavorites()
{
    var title = document.title; var url = location.href;
    if (window.sidebar) // Firefox
	    window.sidebar.addPanel(title, url, '');
    else if(window.opera && window.print) // Opera
    {
	    var elem = document.createElement('a');
	    elem.setAttribute('href',url);
	    elem.setAttribute('title',title);
	    elem.setAttribute('rel','sidebar'); // required to work in opera 7+
	    elem.click();
    } 
    else if(document.all) // IE
	    window.external.AddFavorite(url, title);
}

This function can be used as

<a href="javascript:AddToFavorites();" title="Bookmark this page">Bookmark this page!</a>

This link can be place in any page of your website. Thereby you can reduce the pain of your website user to bookmark or make favorites manually.


Comments

  • wesley says:
    Jul 17, 09

    lol works awsomely, you wont believe how many site just have crap on that only works with IE and those that claim to work with firefox etc are just fail and dont...any idea wats the code to add a bookmark in google chrome.

  • joe says:
    Nov 10, 09

    does not work in any browser

  • kejsu says:
    Feb 05, 10

    that`s right it doesn`t work on ff3.5

  • nandita says:
    Aug 10, 10

    Thanks for the code.works fine for my requirement


Leave a reply


Do you like this post?