Issue
I tried to access some properties (or call methods) defined in http parent window via window.opener in pop-upped https window, which is created from the parent window.But it simply fails when accessing window.opener.a_property in the child window because the protocol is different between the child and parent window. e.g. http and https
Remember this browser behavior is absolutely correct. The point of this post is how to avoid simply stopping javascript when accessing properties in window.opener.
Browsers
I confirmed this permission issue happens FireFox 17.0.1 and Internet Explore 9.Somehow Chrome doesn't complain it at all. the code simply passed.
Solution
In order to avoid this, I wrote the following conditions to detect the window.opener is accessible or not before accessing window.opener, but all of them don't return expected result at all.if(window.opener) // return true :( if(window.opener == undefined) // return true :(Finally I have reached at the following solution.
try{ window.opener.a_property; } catch(e) { // if child window is unable to access parent window, exception is thrown like below. // Error: Permission denied to access property 'a_property' }I have tried bunch of methods but there is no other clean way to detect window.opener is accessible or not. If someone knows more proper way please give me a comment :D
If you are more interested in Javascript, I highly recommend the following book!!
コメント