IE8 上跨域 Iframe 的问题:更改parent.location 会强制新的弹出窗口。如果发生点击事件,它会按预期工作
我在跨域 iframe 通信工作时遇到很多麻烦。
它适用于 Firefox 和 Chrome,但在 Internet Explorer 上,它仅以某些方式起作用:
如果 parent.location = 'new_hash';
未包含在 onClick 事件中,它强制父框架打开一个新的弹出窗口。如果是在 onClick 事件中,则跨域片段标识符技巧起作用。什么给?
听起来我需要理解 javascript..
编辑评论:parent.location.href 和parent.location 具有相同的行为。
这似乎是我的特定浏览器 IE 8.0.7600.16385 将哈希更改作为弹出窗口读取。我想听听其他人是否经历过类似的事情。
在父级中创建弹出窗口:
<script type="text/javascript">
parent.location = 'http://example.com#new_hash';
</script>
在 IE8 中显示“弹出窗口被阻止”对话框。如果我让弹出窗口打开,它们就会无限地打开弹出窗口。
不在父级中创建弹出窗口:
<a onClick="parent.location='http://example.com#new_hash'">clicky</a>
或
$(function() {
$("mybutton").click( function() {
parent.location='http://example.com#new_hash';
});
不在父级中创建弹出窗口。
我的真实示例
需要在其自己的哈希具有特定值时触发parent.location=newhash。我基本上有一个:
setInterval(function() {
if (location.hash == 'something')
{
parent.location='http://example.com#new_hash';
}
}, 500);
发生了什么事?我该如何解决这个问题?为什么它在与单击事件绑定时有效,但如果该语句单独运行则不起作用?我正在研究的具体示例位于 http://www.grovemade.com/products/test< /a> 在 v.04 中,
我在这里积极搞乱,因此它可能会过时。.
在 Firefox 和 Chrome 上, 父框架从无哈希修改为 #xdm-success、#握手完成。
在 IE8 上,#xdm-success 强制打开一个新页面。
谢谢你!
I'm having a lot of trouble getting cross domain iframe communication working.
It's working on Firefox and Chrome, but on Internet Explorer, it only works in some ways:
If the parent.location = 'new_hash';
is not encompassed in an onClick event, it forces the parent frame to open a new popup window. If it is in an onClick event, the cross domain fragment identifier trick works. What gives?
Sounds like I need to understand javascript..
Edit to comments: parent.location.href and parent.location have the same behavior.
It seems to be my specific browser IE 8.0.7600.16385 reading the hash change as a popup. I'd like to hear if anybody else has experienced something like this.
Creates popup in parent:
<script type="text/javascript">
parent.location = 'http://example.com#new_hash';
</script>
shows a "popup blocked" dialog in IE8. If I let the popups open, they infinitely open popups.
Does not create popup in parent:
<a onClick="parent.location='http://example.com#new_hash'">clicky</a>
or
$(function() {
$("mybutton").click( function() {
parent.location='http://example.com#new_hash';
});
Does not create popup in parent.
My real example
Mine needs the parent.location=newhash to fire when its own hash has a certain value. I essentially have a :
setInterval(function() {
if (location.hash == 'something')
{
parent.location='http://example.com#new_hash';
}
}, 500);
What's going on? How can I tackle this problem? Why does it work when tied to a click event but not if the statement runs on its own? The specific example i'm working on is at http://www.grovemade.com/products/test at v.04
I'm actively messing around here so it may become outdated..
On Firefox and Chrome, the parent frame is modified from no hash, to #xdm-success, to #handshake-complete.
On IE8, #xdm-success forces a new page to open.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该设置
parent.location.href
而不是parent.location
吗?我不知道后者根本有效......Shouldn't you be setting
parent.location.href
instead ofparent.location
? I wasn't aware the latter worked at all...我认为对于旧版浏览器,您只需在 iframe 内加载另一个 iframe 并使用 cookie 来获取哈希值即可。
I think for legacy browsers you can just load another iframe inside the iframe and use a cookie to obtain the hash.