Create a function to save a page in Favorites and Bookmarks with javascript

Javascript Function:

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

Using the bookmark function:

<a href="javascript:bookmark(document.title,window.location);">Bookmark this page</a>
<a href="javascript:bookmark('javascript bookmark','http://www.w3mentor.com');">Bookmark this page</a>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.