在打开的窗口中监听 URL 变化
如果我打开一个窗口(使用 window.open
),我可以检测到其 URL 何时发生更改(更改为特定的 URL),前提是:
- 窗口的初始 URL 位于另一个域(Facebook、准确地说)
- 我有兴趣检测的 URL 也
需要它进行身份验证。 请参阅本页底部的“桌面应用”。
If I open a window (with window.open
), can I detect when its URL changes (to a specific one), given that:
- The initial URL for the window is on another domain (Facebook, to be precise)
- The URL I'm interested in detecting is too
I need this for authentication. See "Desktop apps" at the bottom of this page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要新 url 所在的域不被同源策略视为等于您自己的域,那么这是不可能的。
As long as the new url resides on a domain not considered equal to your own by the Same Origin Policy, then this will impossible.
嗯,我发现的一种方法是简单地继续轮询窗口的
location.href
(使用setTimeout
),但这并不优雅。更新:它不起作用。我可以
console.log(newWin.location)
很好,但是当我尝试访问href
或hash
时,我收到跨域安全错误。Well, one way I've found is to simply keep polling the window's
location.href
(usingsetTimeout
), but it's hardly elegant.Update: It doesn't work. I can
console.log(newWin.location)
just fine, but when I try to accesshref
orhash
I get cross-domain security errors.