Forum Moderators: mack

Message Too Old, No Replies

Using Javascript to allow users to bookmark your page

How do I set a javascript bookmark up.

         

TimmyMagic

3:49 pm on Apr 23, 2005 (gmt 0)

10+ Year Member



Hi,

I want a link on my site which bookmarks the site for broswers. I want to use the JS as external. Here is what i put in the head of the page:

<script type="text/javascript" language="javascript" src="/path/filename.js"></script>

And in the external JS file i have put:

<script LANGUAGE="Javascript">
var txt = "bookmark this site";
var url = "http://www.mydomain.com";
var who = "My Domain";
var ver = navigator.appName;
var num = parseInt(navigator.appVersion);
if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
document.write('<A HREF="javascript:window.external.AddFavorite(url,who);" ');
document.write('onMouseOver=" window.status=');
document.write("txt; return true ");
document.write('"onMouseOut=" window.status=');
document.write("' '; return true ");
document.write('">'+ txt + '</a>');
}else{
txt += " (Ctrl+D)";
document.write(txt);
}
</script>

The thing i'm not clear on is what do i put on the link, so it knows which link is to make this happen. I put /bookmark.js, and it worked but sent the broswer to a blank page where you click on the link.

Please can someone explain to a novice.

Thanks,

Tim

P.S. Also, doesn't seem to work for firefox, only IE.

oneguy

7:50 pm on Apr 23, 2005 (gmt 0)

10+ Year Member



I could be wrong, but I don't think you need anything in the head.

You call the script in the body where you would like it to appear.

In the external file, remove the first and last line. (because the script tags are in the body and don't need to be in the external file.)

TimmyMagic

8:53 am on Apr 24, 2005 (gmt 0)

10+ Year Member



Thanks, yes you were right and it now works. However, it only works in Internet Explorer. In both Netscape and Firefox, the text 'Add ****.com to your favourites' appears, but is followed by (Ctrl+D) and also, it doesn't work.

Anyone know what code needs to go into the script to make it compatible with browsers other than IE?

Thanks,

Tim

Jon_King

11:27 am on Apr 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Deleted