开发者

Trouble with Cross Domain Iframes on IE8: changing parent.location forces new popup window. if on a click event, it works as expected

开发者 https://www.devze.com 2023-01-05 22:18 出处:网络
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:

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!


Shouldn't you be setting parent.location.href instead of parent.location? I wasn't aware the latter worked at all...


I think for legacy browsers you can just load another iframe inside the iframe and use a cookie to obtain the hash.

0

精彩评论

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