-1

Possible Duplicate:
Add to browser favorites/bookmarks from javascript but for all browsers (mine doesn't work in CHROME)?

I have this code to bookmark my site on my website and it works great in Explorer, however in Google Chrome and Firefox, it doesn't work.

<p><b>
    <font style="font-family: verdana, sans-serif" size="1" face="verdana, sans-serif">
        <a href="javascript:window.external.AddFavorite('http://yourphotomovie.com','Photo Montage Site')" style="font-size: 2.5mm; font-family: Arial; color: #333333; font-    weight: bold" />
            <img border="0" src="http://yourphotomovie.com/Images/BookmarkUs.jpg" width="115"      height="18">
        </a>
    </font>
</b></p>

Any ideas on how I can make it work?

Community
  • 1
  • 1
Mike
  • 21
  • 7
  • 6
    Never, ever, EVER use IE as a reference for how things should work. Inept at best, IE is the worst browser on the planet! Also, your markup may have worked great in the 1990s but this is 2012. Whatever book you got that markup out of, throw it away. – Rob Apr 16 '12 at 13:43
  • Not sure what you mean Jacktheripper – Mike Apr 16 '12 at 13:45
  • Lol sorry I didn't know will do. I am a complete untrained novice hacking out a website as best I can.Mike – Mike Apr 16 '12 at 13:49
  • In addition, "will not work" is not a technical term. What doesn't work? How is it supposed to work? – Rob Apr 16 '12 at 13:50
  • Nothing happens when button pressed. It is supposed to pull up a Favourites window to enable site to be Bookmarked. – Mike Apr 16 '12 at 13:53
  • Its not my intention to be rude or something but bookmarking scripts are so last millenia :) Most of them are not cross-browser compliant and browser user interfaces have improved so much in the last couple of years that its often much easier to use the built-in bookmarking functionality. –  Apr 16 '12 at 13:53
  • Ok holodoc thanks As I said I am trying to hack out a website. Will do. Thanks – Mike Apr 16 '12 at 13:57

1 Answers1

0

Something like this should do the work:

<script type="text/javascript">
function addToBookmark() {
  // Firefox
  if (window.sidebar) {
      window.sidebar.addPanel(location.href,document.title,"");
  } 
  // IE 
  else if(window.external) {
      window.external.AddFavorite(location.href,document.title); 
  }
  // Opera
  else if(window.opera && window.print) {
      this.title=document.title;
      return true;
  }
}
</script>


#HTML:
<a href="#" onclick="addToBookmark();return false;">Add to bookmarks</a>

I don't remember if this was working with Safari but hopefully somebody with Safari could tell :)

P.S. This code doesn't cover Chrome because of security restrictions. In chrome you should simply advice users to press CTRL+D.

tftd
  • 16,203
  • 11
  • 62
  • 106
  • 1
    tftd I tried it and nothing happens, I will play around with the code and see if I can get it working. Thanks Mike – Mike Apr 16 '12 at 14:05