开发者

Set opener.location in Opera

开发者 https://www.devze.com 2023-01-31 03:16 出处:网络
I have http://parent.com that opens a pop-up on http://parent.com:8888 (this is in development, in production may be even on another domain (that I control)). After the pop-up end it\'s magic it will

I have http://parent.com that opens a pop-up on http://parent.com:8888 (this is in development, in production may be even on another domain (that I control)). After the pop-up end it's magic it will contain this:

 <!-- this is on http://parent.com:8888/popup.php -->
 <html>
     <script type="text/javascript">
         window.opener.location.href = "http://parent.com/ow_yeah.php";
         self.close(); 
     </scr开发者_开发技巧ipt>
 </html>

Works on all browsers, except IE8 and Opera. In IE8 I still have to investigate, but the Opera is the one that bugs me. The error that it throws is this:

Uncaught exception: ReferenceError: Security error: attempted to write protected variable

Tried this but it didn't work. I also read across the internet that this is a cross-domain issue: a child window should never modify something on it's parent form another domain EXECPT the location of the parent. What I try to do is to change the location, but I still have problems. Any ideas ?


Same origin policy is in play here. If you look at the chart you will see that different ports are seen as different domains.


Indeed, it's because a different port is considered a different origin. I'm surprised that you see it fail in only some browsers, but I guess their security policies may be a bit different. Do you set document.domain anywhere, BTW?

If you for some reason really need this setup with popup and parent from different origins, you may have to fall back to using window.postMessage() for communicating between them. See http://ejohn.org/blog/cross-window-messaging/ (a bit outdated in its examples but a pretty good explanation of principles) and http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#web-messaging - the current spec, with copy-pasteable example code.

0

精彩评论

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