tags:

views:

664

answers:

3

I have popup window that is opened through a button click. If the user searches for a particular item in the child window, I attempt to switch the parent windows location by using window.opener.location in the child window. The parent window will always stay within the same website. This works fine in FireFox 3.07 & 3.1 b3, and IE 7&8. But in Chrome 2.0b (dev branch) and Safari 4 Beta (for Windows) i get this strange error:

Unsafe JavaScript attempt to initiate a navigation change for frame with URL

Here is the weird thing, in Safari it never works, but in Chrome it works if:

*Child window is same protocol(HTTP/HTTPS) as the text i am using setting window.opener.location
*Parent window and child window are the same protocol(HTTP/HTTPS)

edit: In Opera it only works if both the parent and child window are HTTPS...

A: 

Would it be better to return a value to the parent window that allows it to then redirect to the correct location? That seems cleaner to me.

searchterm = window.open(...);
Lazarus
thats a good idea. let me do some fiddling and see if i can get something that will work.
Mike_G
from the docs on window.open() the return value is a handle to the window itself. It would likely be easier to call a function on the opener that does the redirect. e.g. window.opener.funcName('special value'); and the opener window would redirect as needed.
scunliffe
another limitation i am running in to is cross site scripting...If the child window is HTTPS, and the parent is http, Safari give me an error, and if I try to window.open() it blocks it as a popup.
Mike_G
A: 

This seems to be a cross site scripting security restriction that webkit and opera impliment and IE and FF ignore.

Mike_G
A: 

I'm having exactly the same difficulty. I'd be grateful if you learned anything about this, if you'd post it!

Mike

I never really found definite answer, but it is related to the security measures that both browsers employ.
Mike_G
I think I've found an explanation:http://developer.apple.com/safari/library/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Articles/Cross-documentmessaging.htmlYou're absolutely right -- the security model in HTML 5 prevents interaction between a pop-up (or an iFrame) if the two windows are on different a different host/domain.Apple has a recommendation for using "postMessage()" to send a message to the opener, but the opener needs a listener, which wouldn't be feasible in my situation.