Wednesday, October 21, 2009

Code for "Bookmark Us" in Javascript

Place the following script into your <head>section in the page you need to use it:

<script type="text/javascript">

function bookmark_us(url, title){

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);
}
</script>

Next, place the following code in order to show the link that opens browser's bookmark window:

<a href="javascript:bookmark_us('http://phpcoders.blogspot.com/','Php Coders')">Bookmark us!</a>

That is all! You have now a full working bookmark us script.

No comments: