这确实让我头疼:
使用 javascript(假设在 page1.html 上),我使用类似于下面的代码来启动一个新窗口:
var popwindow = window.open("http://www.stackoverflow.com");
然后我将 popwindow
变量传递给使用 < code>setTimeout 每 3 或 4 秒重复一次(我认为这部分不太重要)。这个小循环代码的作用是(应该)检查弹出窗口的 location
对象,以查看 url 何时更改并包含某些特定的查询字符串变量。
在大多数情况下,这是有效的;代码重复,并且使用 firebug,我可以看到窗口对象正在按其应有的方式传递。
但我的问题是,每当我尝试访问 popwindow.location.href
或 popwindow.location.search
时,javascript 都会崩溃。我什至只是尝试自己做一个 popwindow.location.toString()
来获取这些东西,但这也会崩溃。
当我使用 firebug 时,我可以看到我尝试访问的 location
对象是合法的 location
实例;当我暂停脚本时,firebug 允许我浏览 location
对象的字段。然而,当我尝试访问这些东西时(我不是写信给它们,只是读取值),它永远不会工作......如果它有帮助,我正在使用最新版本的firefox(我相信是5.0)。
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 firebug, 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).
发布评论
评论(2)
如果引用的窗口与您正在运行的脚本所在的窗口不在同一域中,则浏览器将不允许您访问跨域窗口。它会抛出异常。
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.
来自 https://developer.mozilla.org/En/DOM/Window.open
我怀疑这可能是你的问题。 “同源策略”链接更详细地记录了要求。
From https://developer.mozilla.org/En/DOM/Window.open
I suspect this is probably your problem. The "same origin policy" link documents the requirements in more detail.