从框架内读取父位置(不同域)
iframe 如何读取其父位置 URL,父窗口和 iframe 的域不同?
我知道这个问题的“常见”答案是,由于域冲突,浏览器不允许跨域访问。 因此,以下行不通:
parent.location.href
但也许有人可以在这里跳出框框并提出类似于跨文档消息传递黑客?
How could an iframe read its parent location URL, the domains of the parent window and the iframe being different?
I know that the "common" answer to this question is that because of the domains conflict, browsers don't allow cross-domain accesses.
So the following won't work:
parent.location.href
But maybe someone could think out of the box here and propose something similar to the Cross-document messaging hack?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您可以检查
document.referrer
?当然,只有当用户尚未单击 iframe 内的链接时,这才有效。Perhaps you could check
document.referrer
? Of course, that will only work if the user has not yet clicked a link inside the iframe.我得到了它!!
我的解决方案如下:
1.将 onload 属性与框架结合使用
2.监视框架中的哈希更改
然后“voilà”:-)
顺便说一句,您会发现有关onhashchange 事件。
I got it!!
My solution is the following:
1. Use the onload attribute with the frame
2. Monitor hash changes in the frame
And "voilà" :-)
By the way, you'll find some more details about the onhashchange event.