Forum Moderators: open

Message Too Old, No Replies

How to capture and display URL in new window

         

chessmotifs

7:48 am on Jul 3, 2007 (gmt 0)

10+ Year Member



Hi, I'm new here :)
I hope someone can help me solve this challenge. Here goes.

Example:
I am at page http://www.example.com
I click on this button and a new window pops up.
The content of the new window says... "You arrived here via http://www.example.com"

So, how do I retrieve the current URL and use it as a variable/field on the next window? I know document.location.href gets the current URL, but don't know how to transfer the data over to new window.

Appreciate any help. Thanks! :)

ytswy

8:20 am on Jul 3, 2007 (gmt 0)

10+ Year Member



Hi chessmotifs, welcome to WebmasterWorld!

document.referrer will provide the referrer header as passed by the client browser - you are relying on the browser to tell you the truth however.

chessmotifs

9:15 am on Jul 3, 2007 (gmt 0)

10+ Year Member



hi wtswy,
Thanks for your quick reply! Didn't know there's an easier way to do this. Thanks again.

bear

7:31 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



Hi,

The best way to transfer a variable to a new window is using

window.name

window.name= "variable to be passed"
mynew="window.location= 'openme.html'"
eval(mynew)

in the window that opens

myvar = window.name >>> myvar = "variable to be passed"

It works for me = remember to change the name after you've extracted the varable.

chessmotifs

3:21 am on Jul 4, 2007 (gmt 0)

10+ Year Member



hi bear,
Thanks for your advise too as I tried it out and worked as well for normal windows.

I'm still having some difficulties because I want it to open as a new (separate) popup window with a fixed size. How can I modify it so that it has similar effect as onClick

eg. <span class="popup" onClick=javascript:window.open("new.htm", width=250,height=250")>new window</span>

(and i think because it opens a new window, the document.referrer doesn't work to transfer the old page URL...)

will I still be able to get the data "myvar = window.name;" in the new window?

Lastly, maybe not an appropriate question to post here, on the new window, if I want to input the "myvar" value (which will generate from javascript) into a database (MySQL) using PhP, is it possible?

Thanks for your advise!

bear

5:49 am on Jul 4, 2007 (gmt 0)

10+ Year Member



Hi,

It should work for the new window, and the variable can be used for any purpose as far as I'm aware.

Cheers,