Oliver Tappin
Oliver Tappin

Reputation: 2541

Add to favourites/bookmarks bar in Safari (CMD +D)

From much research, I have found nothing that supports the idea that Safari even supports this feature. From how much API there is for Safari, I can't believe that they wouldn't allow this to be embedded with their browser.

If anyone has any ideas of how this can be achieved without using some horrible plugin that doesn't actually work, it would be greatly appreciated.

So far, I have taken care of the main browsers by using this:

$("#bookmark").click(function() {
  var url = this.href;
  var title = this.title;
  if($.browser.mozilla) {
    window.sidebar.addPanel(title, url,"");
  } else if($.browser.msie || $.browser.webkit) { 
    window.external.AddFavorite(url, title); 
    if($.browser.safari) {
      alert("Balls");
    }
  } else if($.browser.opera ) {
    $(this).attr("href", url);
    $(this).attr("title", title);
    $(this).attr("rel", "sidebar");
    $(this).click();
  } else {
    //alert("Please press CTRL+D and click the link to bookmark it in your browser.");
  }
  return false;
});

Upvotes: 1

Views: 1747

Answers (1)

Mark Pieszak - Trilon.io
Mark Pieszak - Trilon.io

Reputation: 67121

Unfortunately Safari does not allow you to add a bookmark through javascript (along with IE6/IE8) and possibly a few others. It's some sort of attempt at fighting off spam/unwanted websites adding bookmarks to your browser onload.

Try a script like this, it's pretty much all you can do...

$("a.bookmark").click(function(e) {
            if ($.browser.opera == false) {
                    e.preventDefault();
                    var url = this.href;  
                    var title = this.title;

                    if ($.browser.mozilla == true) {
                            window.sidebar.addPanel(title, url, '');
                            return false;
                    } else if($.browser.msie == true) {  
                            window.external.AddFavorite( url, title);
                            return false;
                    } else {
                            alert('Please use CTRL + D to bookmark this website.');
                    }


    }
});

Info from Apple forums (https://discussions.apple.com/thread/1364657?start=0&tstart=0)

Upvotes: 2

Related Questions