views:

2180

answers:

4

I tried some "add to favorties" JavaScript scripts.. With IE8, I get an "access denied" (is that even possible to add a bookmark via JS with IE8?) and it just doesn't work with IE6... Anybody has a good script that works on most browsers?

Thanks!

A: 

Hi,

Both IE6 and IE8 will need the users to press CTRL+D to add the website to the favourites.

Edit: Sorry, I run into a brain malfunction and mixed some words out.

Actually, IE8 allows javascript to manage the favourites.

To be more precise, and if you use jquery on your website, here's an example :

    $("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.');
          }


    }
});

Note: the "a.bookmark" is required to work with opera, since it recognizes .bookmark class in anchor tags and executes the bookmark funcion on click.

It supports IE7 & 8, Firefox 2 & 3, and Opera 9 (at least) .. Safari isn't supported, and IE6 I couldn't test it here, sorry.

yoda
ok, thank you for your answer!
But the answer is wrong. Or at least not the whole truth.
roosteronacid
A: 

This solution looks solid. But I'd recommend that you test it across whatever browsers you plan to support.

roosteronacid
A: 

thank you very much, it works nicely

TStar
+1  A: 

I have a client who wants this. So far as tested this is a totally 100% cross platform solution. Not only does it give the standard bookmarking functionality, but it educates your user at the same time :) :) :)

I've tested it as working on Chrome, Firefox and IE.

Code is below:

<a class="button" onClick="alert('Hold down Ctrl and D at the same time to add this to your favourites')">Bookmark</a>

.. now the real question is whether to use confirm or alert. Confirm may give the users a reassuring but false sense of control about whether they added the bookmark or not?

John Deverall