Trouble retrieving window location from a previously opened window ?

M

Mark

Hi,

I am trying to open up a new window and then get the current url/location
back from the (win_1) window and display the url in an alert box.


Here is the code I am using :-

<script type="text/javascript">
var mywin_1 = open ("http://www.anysite.com/index.htm", "win_1",
"height=640, width=820, left=200, top=0, scrollbars, status, location");
var temp = mywin_1.location;
alert (temp);
</script>


Where am I going wrong?


Thanks in advance, Mark
 
L

Lee

Mark said:
Hi,

I am trying to open up a new window and then get the current url/location
back from the (win_1) window and display the url in an alert box.


Here is the code I am using :-

<script type="text/javascript">
var mywin_1 = open ("http://www.anysite.com/index.htm", "win_1",
"height=640, width=820, left=200, top=0, scrollbars, status, location");
var temp = mywin_1.location;
alert (temp);
</script>


Where am I going wrong?

1. You should specify window.open(), because there is also a document.open()
method. That's not causing you any problems, though.

2. As written, I see the alert: "about:blank" in Firefox, because you're
trying to read the location too soon after the window.open() call.
The browser hasn't even had time to contact the "www.anysite.com",
server, let alone load the new page.

3. You should be alerting the value of location.href, rather than location,
if only because the resulting error message is easier to understand.

4. If you do add a delay, and you do alert the value of location.href, you
will see an error message telling you that you don't have permission
to read the location of a window open on a site that differs from the
site that served the current page. It's a security feature to prevent
people from popping up new windows and then keeping track of where the
user navigates in that window.
 
M

Mark

Lee said:
Mark said:

4. If you do add a delay, and you do alert the value of location.href, you
will see an error message telling you that you don't have permission
to read the location of a window open on a site that differs from the
site that served the current page. It's a security feature to prevent
people from popping up new windows and then keeping track of where the
user navigates in that window.

Hi,

Thanks for your help on items 1 - 3.

The problem I was having (using Internet Explorer) was that it didnt
acutally display any alert at all (though did say access denied if I
double-click on the '!' on the status bar) obviously I now understand why.


Item #4 - I can understand about the security prevention, but I thought I
would be able to get around this with myself opening the window originally.
There must be some way to get the URL of an open window which the code is
not running in ? Any advice?

The web page in question is for use internally on a standalone machine so I
can lower any 'restrictions' in the actual browser if this needs to be ?



Thanks, Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top