IE Overwrite window.top

2019-02-19 20:55发布

I'm trying to convince a page that it is the window.top even though it is in an iframe.

In FF you can do

window.defineGetter('top', function() { return window});

in Webkit (Safari/Chrome) you can simply do

window.top = window

but in IE none of those methods work. Anyone done this before?

4条回答
爷、活的狠高调
2楼-- · 2019-02-19 21:27

Try window.top = window.top.window

More details on DOM Window.

查看更多
smile是对你的礼貌
3楼-- · 2019-02-19 21:28

Setting window.top doesn't work. Its not allowed in IE.

I ended up having to make my own fake window object, fill it with most of the properties of the window object, and then making a fake .top property.

查看更多
等我变得足够好
4楼-- · 2019-02-19 21:31

I'd maybe try using the "define getter" notation that John Resig uses in his article on the topic:

Window.prototype.__defineGetter__('top',function(){return this;});

查看更多
小情绪 Triste *
5楼-- · 2019-02-19 21:46

Use this:

Object.defineProperty(window, "parent", { 
        get: function() {return window;} 
    }
);

More info here.

查看更多
登录 后发表回答