防止iframe更改父位置 [英] prevent iframe from changing parent location

查看:149
本文介绍了防止iframe更改父位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设 http://a.com/foo 包含< iframe src =http:// b.com/bar\">

有时b.com/bar会突破其框架:顶级窗口将重定向远离a.com/foo进入b.com/bar。我不知道b.com是如何做到的。

Sometimes b.com/bar will break out of its frame: the top-level window will redirect away from a.com/foo into b.com/bar. I don't know how b.com is doing this.

我认为跨域iframe不可能干扰父母,除非父母合作通过postMessage。是否正在更改窗口位置?

I thought it wasn't possible for a cross-domain iframe to interfere with the parent unless the parent cooperates via postMessage. Is changing the window location exempt from this?

如果发生了这种情况,a.com如何阻止此重定向?我控制a.com但不能修改b.com。

If that is what's happening, how can a.com prevent this redirect? I control a.com but cannot modify b.com.

如果那不是正在发生的事情,我怎样才能知道b.com正在做什么来实现重定向?

If that's not what's happening, how can I find out what b.com is doing to achieve the redirect?

强制b.com将自己加载到新窗口,或破坏其对 top 或对象。 b.com行为的其他降级可能是可以接受的。

It would be acceptable to force b.com to load itself into a new window, or sabotage its access to the top or parent objects. Other degradations of b.com's behaviour may be acceptable.

推荐答案

父母可以使用沙箱 iframe 上的$ c>属性:

http://www.w3schools.com/TAgs/att_iframe_sandbox.asp

Parent can use sandbox attribute on iframe:
http://www.w3schools.com/TAgs/att_iframe_sandbox.asp

然后 iframe 将无法再重定向父级。

Then iframe will no longer be able to redirect parent.

这篇关于防止iframe更改父位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆