View Full Version : Add to favorites code
What are the mechanics behind those "add this site to favorites" or "make site homepage" buttons. How do they work when the person clicks on them. Does it automatically add the site to the favorites or make it the home page? If it does, does anybody know the code for them?
AndyH
08-07-2005, 12:13 AM
For "Make Homepage" I use this: (IE only)
<a href="" onClick="this.style.behavior='url(#default#homepage)'; this.setHomepage('http://www.example.com'); return false;">Make Homepage</a>
It prompts the visitor to comfirm. If they click "Yes" it is then made the homepage.
James
08-07-2005, 02:03 AM
<a href="" onclick='window.external.AddFavorite(location.href ,document.title);'>Make Homepage</a>
According to a Google search, that code should add the page they're currently on to their favourites.
Basically, the way code like this works is that the browser will have the function understood and used by the browser--at least from what I've heard, but my old Javascript teacher was a bit qwerky, and was "teaching" from a textbook that still recognized IE4 and NS4 as the 2 standards, and said that you should make different sites for each browser (aka browser war period).
Thanks, I'll have to give them a try when I get back to my computer with all my website building stuff on it.
Cutter
08-07-2005, 02:08 PM
I have some code I'm using on one site which is cross-browser compatible. I'll look it up and post a link.
Westech
08-07-2005, 05:45 PM
I'd love to see the cross-browser compatible code if you can find it. Right now I'm just using "Press crtl+D to add this page to your favorites" because I haven't been able to find a javascript method that works in all browsers.
Cutter
08-08-2005, 09:14 AM
Try this, I wish I could credit it, but I can't find the URL:
<script> <!-- Begin
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
var url="http://www.yourdomain.com";
var title="Your Site Name";
document.write('<A HREF="javascript:window.ext');
document.write('ernal.AddFavorite(url,title);" ');
document.write('onMouseOver=" window.status=');
document.write("'Click here to add our site to your favorites!'; return true ");
document.write('"onMouseOut=" window.status=');
document.write("' '; return true ");
document.write('">Click here to add our site to your favorites!</a>');
}
else {
var msg = "Bookmark us!";
if(navigator.appName == "Netscape") msg += " (CTRL-D)";
document.write(msg);
}
// End -->
</script>
Westech
08-08-2005, 09:36 AM
Thanks a lot Cutter! I'll give this a try when I find some spare time.
moonshield
08-08-2005, 09:48 AM
ah nice! Thanks.
James
08-08-2005, 01:08 PM
Shouldn't that just display the popup "CTRL-D" if a Gecko-based browser goes to the site?
Surely there's a way to cause gecko-based browsers to actually bookmark the URL?
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.