1

I am trying to find out the protocol used by a parent window in a child window. If I use window.opener.location.protocol, it works in everything (IE8, FF3.5.5, Safari4.0.3, Chrome4) except Opera. In opera i get:

message: Security error: attempted to read protected variable 'protocol'

This used to work fine in Opera, but I guess they changed it. I am using Opera 10.10. Is there any way to test for the protocol, or even determine if the parent window is the same location and protocol as the child?

Mike_G
  • 16,237
  • 14
  • 70
  • 101
  • What are the urls of the parent and child windows? – SLaks Dec 07 '09 at 14:15
  • They are different the child window is http, and the parent is https. But i just need a way to determine it without testing window.opener.location.protocol – Mike_G Dec 07 '09 at 14:18

1 Answers1

1

You should only get the error when the protocols are different.

In other words:

var isParentSecure;
try {
    isParentSecure = window.opener.location.protocol === 'https';
catch(e) { isParentSecure = window.location.protocol !== 'https'; }

I haven't actually tested this.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • This question has some details to back up location.protocol http://stackoverflow.com/questions/282444/how-can-i-use-javascript-on-the-client-side-to-detect-if-the-page-was-encrypted – Dylan Valade Apr 09 '12 at 05:36