开发者

javascript window.location not working in firefox

this one is really giving me a headache:

using javascript (let's say on page1.html) i use code similar to below to launch a new window:

var popwindow = window.open("http://www.stackoverflow.com");

i then pass the popwindow variable to a function that uses setTimeout to repeat every 3 or 4 seconds (this part is not too important i do not think). what this little looping code does is (supposed to) check the location object of the popup window to see when the url changes and contains some certain query string variable.

for the most part, this is working; the code repeats, and using fi开发者_如何学运维rebug, i can see that the window object is getting passed as it should.

my issue though is that whenever i try to do any access to popwindow.location.href or popwindow.location.search, javascript crashes. i even simply tried to do a popwindow.location.toString() to get this stuff out myself, but that crashes as well.

when i use firebug, i can see that the location object that i am trying to access is a legit location instance; firebug allows me to browse the location object's fields when i have the scripts paused. however, when i try to access these things (i am not writing to them, only reading the values) it will never work... in case it is helpful, i am using the latest version of firefox (5.0 i believe).


If the referenced window is not on the same domain as the window that the script you're running is in, then the browser won't let you access cross domain windows. It will throw an exception.


From https://developer.mozilla.org/En/DOM/Window.open

windowObjectReference

This is the reference pointing to the newly created browser window. This reference is the return value of the open() method; it will be null if for some reasons the execution did not succeed to open the window. A global variable is best used to store such reference. You can then, for example, use it to look for properties of the new window or access its methods, assuming that your main versus secondary window relationship complies with Same origin policy security requirements.

I suspect this is probably your problem. The "same origin policy" link documents the requirements in more detail.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜