Skip to content

Instantly share code, notes, and snippets.

@fuhoi
Created June 28, 2011 05:32
Show Gist options
  • Save fuhoi/1050557 to your computer and use it in GitHub Desktop.
Save fuhoi/1050557 to your computer and use it in GitHub Desktop.
html-add-to-favourites
<html>
<head>
<title>JavaScript - Add to favourites</title>
</head>
<body>
<input type="button" value="Add to favourites" onclick="addToFavorites('Google','http://www.google.com');" />
<script language="javascript">
function addToFavorites(name,url) {
if(window.external){ // ie
window.external.AddFavorite(url,name)
} else if(window.sidebar){ // firefox
window.sidebar.addPanel(name, url, "");
} else if(window.opera && window.print){ // opera
var _e = document.createElement('a');
_e.setAttribute('href',url);
_e.setAttribute('title',name);
_e.setAttribute('rel','sidebar');
_e.click();
} else {
alert("Cannot add favourite due to browser support.");
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment