Skip to content Skip to sidebar Skip to footer

Bookmark Javascript Not Jquery For Website

I have the following bookmark Javascript. function bookmark(title, url) { if(document.all) { // ie window.external.AddFavorite(url, title); } else if(window.sidebar

Solution 1:

Here's how to use the answer from How do I add an "Add to Favorites" button or link on my website? without the jQuery event binding.

functionbookmark(title, href) {
    if (window.sidebar && window.sidebar.addPanel) { // Mozilla Firefox Bookmarkwindow.sidebar.addPanel(title,href,'');
    } elseif(window.external && ('AddFavorite'inwindow.external)) { // IE Favoritewindow.external.AddFavorite(href,title); 
    } elseif(window.opera && window.print) { // Opera Hotlistthis.title=title;
        returntrue;
    } else { // webkit - safari/chromealert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != - 1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');
    }
}

Solution 2:

There are some problem with the above solution.

window.sidebar.addPanel("", "","");

The above code may not work in all Mozilla Firefox versions. So I wrote the bookmaking code as below. It will work fine in all browsers except webkit - safari/chrome.

Add "a" tag as shown below

<a id="BookmarkMe" href="">Bookmark</a>

And used below Jquery

$(function () {
            $('#BookmarkMe').click(function (e) {
                var bTitle = document.title, bUrl = window.location.href;
                if ($.browser.mozilla || $.browser.opera) { // Mozilla Firefox or Operaif (window.sidebar.addPanel) {
                        e.preventDefault();
                        window.sidebar.addPanel(bTitle, bUrl, "");
                    }
                    else {
                        $('#BookmarkMe').attr("href", bUrl);
                        $('#BookmarkMe').attr("title", bTitle);
                        $('#BookmarkMe').attr("rel", "sidebar");
                    }
                } elseif ($.browser.msie) { // IE Favorite
                    e.preventDefault();
                    window.external.AddFavorite(bUrl, bTitle);
                } else { // webkit - safari/chrome
                    e.preventDefault();
                    alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');
                }
            });
        });

Post a Comment for "Bookmark Javascript Not Jquery For Website"