Add bookmark script - working cross browser

11/22/2008 11:43:40 AM

I got a lot of questions about getting the perfekt working 'add bookmark script' at your website.

Since I did start working with bookmarks and quick methods to add a bookmark to a website, I have created a cross browser working bookmark script in javascript, and of cause want to share it with your all, it's quite simple and easy to implement.

Bookmark script

/* add bookmark script */
function addBookmark(title,url){
if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
} 
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}

The script above is very easy to setup, just paste it into a .js file, or implement it at your tags. If your want to have a smart submit link, where you don't need to update the submission text, here is anohter tip, using my addBookmark script above.

Bookmark link using the bookmark script

<a href="javascript:void(0)" title="Bookmark this website" onclick="addBookmark(document.title,window.location);">Bookmark this website</a>

Hope you can use this tips by getting a cross browser bookmark script, working on all most popular browsers. Have a nice weekend!



Kommentarer

Der er ingen kommentarer skrevet

Tilføj en kommentar

Navn
Email (Bliver ikke vist på siden)
Hjemmeside
Hvad er 2 + 1?
Kommentar
 
Copyright © 2005 - 2010 Daniel Nøhr. All rights reserved