Cross-Browser Bookmark/Add to Favorites JavaScript

Cross-browser bookmark/add to favorites JavaScript

jQuery Version

JavaScript (modified from a script I found on someone's site - I just can't find the site again, so I can't give the person credit):

$(document).ready(function() {
$("#bookmarkme").click(function() {
if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(location.href,document.title,"");
} else if(window.external) { // IE Favorite
window.external.AddFavorite(location.href,document.title); }
else if(window.opera && window.print) { // Opera Hotlist
this.title=document.title;
return true;
}
});
});

HTML:

<a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Bookmark This Page</a>

IE will show an error if you don't run it off a server (it doesn't allow JavaScript bookmarks via JavaScript when viewing it as a file://...).

Add to browser favorites/bookmarks from JavaScript but for all browsers (mine doesn't work in Chrome)?

Sorry, but there's no cross-browser way to do this. Your FF example is broken as well: It won't create a regular bookmark, but a bookmark set to be opened in the sidebar. You'd have to use the bookmark-service to create an actual bookmark, but this'll fail due to security restrictions.

How to create a Bookmark this page button?

Once upon a time, this could be done. But unscrupulous sites would abuse the capability, forcibly bookmarking sites the user didn't want bookmarked. Now it is no longer possible for pages to add bookmarks on behalf of the user.

Make browser bookmark my link?

From Vaadin you can execute any javascript code you wish.
In the book of vaadin there is a example on how to acomplish it.

In short you can execute any JS code with this method:

// Shorthand
JavaScript.getCurrent().execute("alert('Hello')");

Of course you will need to find the correct JS code to bookmark your page.
If you wish to bookmark a specific application state/view, then you can use the Navigator for this. (It basically adds a #SomeState to your URL which you can the later come back)

How do I add an Add to Favorites button or link on my website?

jQuery Version

$(function() {  $('#bookmarkme').click(function() {    if (window.sidebar && window.sidebar.addPanel) { // Mozilla Firefox Bookmark      window.sidebar.addPanel(document.title, window.location.href, '');    } else if (window.external && ('AddFavorite' in window.external)) { // IE Favorite      window.external.AddFavorite(location.href, document.title);    } else if (window.opera && window.print) { // Opera Hotlist      this.title = document.title;      return true;    } else { // webkit - safari/chrome      alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');    }  });});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Bookmark This Page</a>

Javascript bookmark button

Yep - without giving you the best way of doing it - here's a horrible DHTML solution:
http://www.dynamicdrive.com/dynamicindex9/addbook.htm



Related Topics



Leave a reply



Submit