Forum Moderators: open

Message Too Old, No Replies

Link to bookmark current URL

On dynamically-generated pages

         

MatthewHSE

4:43 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm no JavaScript expert, so please bear with me if this is a basic question.

I want to include a link on many of my pages to bookmark the page. I'm sure everyone is familiar with the concept. IE users are presented with a link to click that pops up their "Add to Favorites" window. Netscape users get a message telling them to use CTRL-D on their keyboard.

I found a script at javascriptsource.com that is almost what I need. The problem is, the script (see below) hard-codes the URL to be bookmarked. This won't work on my site because I'm using mostly dynamically-generated pages. The code for the "Bookmark page" script will be in templates that will be used for many different URL's.

So my main question is, what JavaScript can I use to grab the current URL from the address bar and use it for the IE "Add to Favorites" process? Or, how can I modify the below script to accomplish the same purpose?

Any ideas will be appreciated. I've searched here and w3schools.com with no luck so far. Hope somebody can help!

Thanks,

Matthew

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source! [javascript.internet.com...] -->

<!-- Begin
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {

var url="http://www.javascriptsource.com";
var title="The JavaScript Source";

document.write('<A HREF="javascript:window.ext');
document.write('ernal.AddFavorite(url,title);" ');
document.write('onMouseOver=" window.status=');
document.write("'Add our site to your favorites!'; return true ");
document.write('"onMouseOut=" window.status=');
document.write("' '; return true ");
document.write('">Add our site to your favorites!</a>');
}
else {
var msg = "Don't forget to bookmark us!";
if(navigator.appName == "Netscape") msg += " (CTRL-D)";
document.write(msg);
}

// End -->
</script>

ajkimoto

5:58 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



MatthewHSE,

I think that 'window.location.href' and 'document.title' is what you need.

Try changing:

var url="http://www.javascriptsource.com";
var title="The JavaScript Source";

to:

var url=window.location.href;
var title=document.title;

That should do the trick...

ajkimoto