Mike_G
Mike_G

Reputation: 16502

Testing for parent window protocol in Opera

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?

Upvotes: 1

Views: 636

Answers (1)

SLaks
SLaks

Reputation: 887469

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.

Upvotes: 1

Related Questions