views:

31

answers:

1

Hi everyone,

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'"&gt;clicky&lt;/a&gt;

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!

+1  A: 

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

no
+1 aha! nice eye you got there...
Reigel
Hey there, thanks for the comment. It doesn't make a difference unfortunately. Behavior is the same on IE, Chrome and Firefox. I tested the base, simple example too: an iframe with <script>parent.location.href</script>If it's in a click event, it works as expected. If not, it creates popups.. : (
Yuji
Here's some other things you can try... set the hash directly: `parent.location.hash='new_hash';` or use location.replace: `parent.location.replace('http://example.com#new_hash')`
no
Thanks for the help! Setting parent.location.hash would give me a permission denied for cross domain issues. parent.location.replace gives me the same popup problem. It looks to be unique to my browser.. I tried another IE8 that works just fine. Now I have to track down how often this happens on various IE8s.
Yuji
^ The joys of javascript and internet explorer
Chris T
Ah, it's cross-domain? That's probably the issue. Does this happen when it's not cross-domain? Does it happen in IE9? If (1:no, 2:yes) then it's probably by design, to defeat XSS attempts. One of IE's zillion security settings, maybe?
no
Yeah, it's cross domain. BUT, cross domain works IF its in an onClick event <a onClick> or jquery Click. That's why I'm half stumped, half VERY curious about how these things work.I wish it would at least /fail/ instead of create an infinite series of popups for the user, like we're a spam site of the old ages. -- am now going through the security settings.
Yuji
I will try actually simulating the click event, since it works there! yaay, I have high hopes.
Yuji
Nice idea, let us know if it works :)
no
Didn't work. document.getElementById('test').click(); generates a popup on the parent. Actually clicking on the button silently updates the hash.IDing the problem seems to be in there.. What's the difference between function X being called by a click event, as opposed to the initial parsing?I'm glad I see a light though -- as long as it works during the click event, I can probably work around that and pass a session ID of the iframe to the parent.
Yuji