javascript add bookmark or add favorite function tutorial
A simple cross-browser bookmarking / add to favorites script that works in IE6+ ,FF2+,Opera 7+.Adding the "bookmark this page" javascript below will help to encourage your site return visits. To add this link just copy paste a small script at your link position.it will add only supported browsers.
Download source code
bookmark
javascript code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| <script >
function bookmark() {
title =document.title;
url = document.location.href;
if (window.sidebar) { //firefox bookmark functionality
window.sidebar.addPanel(title, url,"");
} else if( window.external ) { //ie favorite functionality
window.external.AddFavorite( url, title);
}else if(window.opera){//opera virtual sidebar link
a = document.createElement("A");
a.rel = "sidebar";
a.target = "_search";
a.title = title;
a.href = url;
a.click();
}
}
function bookmarklink(){
if (window.sidebar || window.external || window.opera) { //we build link for only supported browsers
document.write('<a href = "javascript:bookmark()");">Add to Favorites</a>');
}
}
</script> |
html code
1
2
3
4
5
6
7
8
9
10
| <html>
<head>
<title>javascript bookmarking for firefox/IE/Safari</title>
</head>
<body>
<script >
bookmarklink();
</script>
</body>
</html> |
Download source code
bookmark