Permission denied to get property Location.href

R

Robert Mark Bram

Hi All!

I have a piece of JavaScript that attempts to find the location.href
property of another window. For example:

contentWindow =
window.open('', 'someWindowName');
var otherUrl = contentWindow.location.href;

If it happens to find a window named 'someWindowName' that currently has a
document loaded from some other host, the "contentWindow.location.href" code
triggers the following error:
Error: uncaught exception: Permission denied to get property
Location.href

I know I could put this code inside a try-catch. However, while I found this
works on IIS5.1 (my testing server), I also found that the version of
Chilisoft I have to use on the production server does not support
try-catch...

So my question is this: how can I avoid the uncaught exception in this case
without using a try-catch?

Thanks for any advice!

Rob
:)
 
T

Tim Williams

Rob,

Your quoted code looks like client-side script, so I'm puzzled as to what
possible effect your hosting server ASP environment might have. Use of
try/catch on the *client* is dependent only on the browser and the js
version it supports....

Tim
 
R

Robert Mark Bram

Howdy Tim!
Your quoted code looks like client-side script, so I'm puzzled as to what
possible effect your hosting server ASP environment might have. Use of
try/catch on the *client* is dependent only on the browser and the js
version it supports....

Of course you are right - I was thinking about the error message without
thinking about it coming from client side. Ignoring the try-catch issue, the
problem is the same: how can I avoid this error:
Error: uncaught exception: Permission denied to get property

Rob
:)
 
M

Martin Honnen

Robert said:
I have a piece of JavaScript that attempts to find the location.href
property of another window. For example:

contentWindow =
window.open('', 'someWindowName');
var otherUrl = contentWindow.location.href;

If it happens to find a window named 'someWindowName' that currently has a
document loaded from some other host, the "contentWindow.location.href" code
triggers the following error:
Error: uncaught exception: Permission denied to get property
Location.href

Well, you can't change that, as you yourself write the document in the
other window is loaded from some other host, and the same origin policy
prevents script from one host to access properties of pages from another
host. If the hosts are in the same domain e.g.
host1.domain.tld
and
host2.domain.tld
then you can set
document.domain = 'domain.tld'
and the cross frame scripting should work, but if the hosts are in
different domains then there is nothing you can do, unless it is
Mozilla/Netscape where you could work with signed script.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top