Created
June 28, 2011 05:32
-
-
Save fuhoi/1050557 to your computer and use it in GitHub Desktop.
html-add-to-favourites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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