Forum Moderators: open

Message Too Old, No Replies

Passing current URL to PHP through link

JS Problem

         

shasan

2:58 am on Aug 30, 2003 (gmt 0)

10+ Year Member



hi Guys,
I'm new to JS, so please bear with me :)

I need to send the URL of the current page as a parameter to another page. I'm doing it through a link, here's how I'm building the link:

function thispage()
{
var thelink="If you liked this page, and would like to send it to a friend,";
thelink += "<a href='http://www.example.com/sendpage.php?refer_url=" + location.href;
thelink +="'>click here!</a>";
document.write(thelink);
}

And in the HTML body, I call the function like this:

<script>thispage();</script>

But it doesn't work. Am I being too naive to think that would work without calling it from an 'event' like OnClick or somethign?

Please help!

cheers

MonkeeSage

3:04 am on Aug 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Should work the way it is, but be careful of your quotes...

thelink +="'>click here!</a>";

...got an orphan in there. Make JS die with an unterminated string literal I would think. Fix that and you should be good to go. :)

Jordan

Ps. I mean it needs to be in the same line, like...

thelink += "<a href='http://www.example.com/sendpage.php?refer_url=" + location.href +
"'>click here!</a>";

shasan

3:27 am on Aug 30, 2003 (gmt 0)

10+ Year Member



Thanks Jordan!

That did the trick... I wasn't sure of how to continue the line after the location.href... thx!