在Opera中测试父窗口协议

时间:2009-12-07 14:07:16

标签: javascript

我试图找出子窗口中父窗口使用的协议。如果我使用window.opener.location.protocol,它适用于除Opera之外的所有内容(IE8,FF3.5.5,Safari4.0.3,Chrome4)。在歌剧中我得到:

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

这曾经在Opera中运行良好,但我猜他们改变了它。我正在使用Opera 10.10。有没有办法测试协议,甚至确定父窗口是否与孩子的位置和协议相同?

1 个答案:

答案 0 :(得分:1)

您应该只在协议不同时才会收到错误。

换句话说:

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

我实际上没有测试过这个。