“Favorite” Link — How To Create a Bookmark Link
I get a lot of requests from customers to add a link to their website that allows the user to "bookmark" their site. I generally try to get them to drop that idea. The functionality of an "add to favorites" link isn't cross-browser compatible -- neither Firefox or Opera will allow it. Internet Explorer does allow favorite links and most of the internet still uses IE, so I do have a script to accomplish this goal.
The Code
/* BOOKMARK THE PAGE */
function bookmark()
{
if ((navigator.appName == 'Microsoft Internet Explorer') && (parseInt(navigator.appVersion) >= 4))
{
window.external.AddFavorite(window.location,document.title);
}
else
{
alert('Don\'t forget to bookmark us! (CTRL-D)');
}
}
The Explanation
It's a pretty simple JavaScript function. The function first checks to see if the user is browsing using Internet Explorer. If so, the function makes the appropriate call to IE, providing the page URL and title. If the user doesn't use Internet Explorer, short instructions are provided to prompt the user's browser to to add the current page as a favorite.
![7 Essential JavaScript Functions]()
I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener and attachEvent. Times have changed but there are still a few functions each developer should...
![9 Mind-Blowing Canvas Demos]()
The <canvas> element has been a revelation for the visual experts among our ranks. Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead. Here are nine unbelievable canvas demos that...
![MooTools Window Object Dumping]()
Ever want to see all of the information stored within the window property of your browser? Here's your chance.
The XHTML
We need a wrapper DIV that we'll consider a console.
The CSS
I like making this look like a command-line console.
The MooTools JavaScript
Depending on what you have loaded...
![HTML5’s placeholder Attribute]()
HTML5 has introduced many features to the browser; some HTML-based, some in the form of JavaScript APIs, but all of them useful. One of my favorites if the introduction of the placeholder attribute to INPUT elements. The placeholder attribute shows text in a field until the...
Nice post. Are you calling the bookmark function when the page loads? It seems like it since the else statement is an alert box. Perhaps a better way is by calling the function onclick of a link. Like you, I wouldn’t personally want to add this, but I think targeting specific browsers and using the addons that each browser offers is a good thing if you can provide a better experience without affecting the other visitors.
No Jeremy, the function isn’t run when the page loads. You would simply call this function from a link.
Calling this implicitly for all users would be website suicide.
why only work for IE when no one uses that?
Bangladesh varsity information and admit
Nice post. I saw a similar script on another website and was wondering why it didn’t work on my Firefox.
Thanks to the iPad and similar devices, this will become obsolete.
Is this functional on all browser? I think i should try the code myself. Thanks for sharing. But if you got an idea already, please tell me or send me the right script for cross browser for bookmark us script. Thanks.
Thank you so much, I’ll be putting your code at my sites. I already tried it and it works like a charm. Your the best admin. Home you can modify it on firefox so that the popup bookmark will be the same result as I.E. Thanks. I appreciate your help!