Forum Moderators: phranque

Message Too Old, No Replies

Code to let visitors make site as homepage

and add site to favorites

         

PFOnline

8:26 pm on Jun 30, 2003 (gmt 0)

10+ Year Member



Hi, anyone know the code to make a link that lets visitors set your site as there homepage, and make a link to let visitors add the site to there favorites? (For internet explorer)

Thanks. :)

claus

8:34 pm on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a little javascript snippet that does the trick for IE as well as other browsers - you don't have to credit me or anything, just copy and paste :)

/claus


<script type="text/javascript">

var IEstring = "<a href='javascript:window.external.AddFavorite"
IEstring += "(location.href,document.title);'>Click here to bookmark this page!<\/a>" ;

var NSstring = "Click [Ctrl + D] to bookmark this page!";

var OTHstring = "Remember to bookmark this page!"

var whichString = OTHstring ;

var agt = navigator.userAgent.toLowerCase();
var app = navigator.appName.toLowerCase();

var ieAgent = agt.indexOf('msie');
var nsAgent = app.indexOf('netscape');

if (ieAgent != -1) {
whichString = IEstring;
} else if (nsAgent != -1){
whichString = NSstring;
}

document.write("<b>" + whichString + "</b>")
</script>

SlyGuy

8:40 pm on Jun 30, 2003 (gmt 0)

10+ Year Member



Hey PFOnline,

To add to favorites:

<span style='cursor:hand;text-decoration:underline;'onclick='window.external.AddFavorite(location.href,document.title);'>
Click to add this page to your favorites list</span>

To set homepage:

<span style='cursor:hand; color:blue; text-decoration:underline'
onClick='this.style.behavior='url(#default#homepage)';
this.setHomePage('http://www.yourdomain.com');'>
Click to set this page as your homepage</span>

HTH..

- Chad

PFOnline

8:43 pm on Jun 30, 2003 (gmt 0)

10+ Year Member



Thanks claus, Sly!

Cheers

PFOnline

10:13 pm on Jun 30, 2003 (gmt 0)

10+ Year Member



The code to set homepage doesn't seem to be working, but I'm just testing it in a blank file, does it have to be uploaded to the domain?

claus

11:13 pm on Jun 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this, but give an alternative for users of other browsers than IE - it will only work in IE:

<a href="#" onClick="this.style.behavior='url(#default#homepage)';
this.setHomePage(location.href);">Set homepage</a>

The difference from the above is that here it is a link, in the above post it is a "span".

oh.. and i use the location.href, so you can just drop it on any page :)

oh..again.. i just saw what went wrong...the '-character should be an " in SlyGuys example

- here: onClick='this.style (after =)

- and here: yourdomain.com');'> (just the one before > )

I think SlyGuys example will work as well if You replace the two 's

/claus