有没有一种方法可以防止iframe重定向父窗口,但是以这样的方式,即“顶级”重定向仍然在iframe内部工作? [英] Is there a way to prevent an iframe from redirecting parent window, but in such a way that "top level" redirects still work inside the iframe itself?

查看:98
本文介绍了有没有一种方法可以防止iframe重定向父窗口,但是以这样的方式,即“顶级”重定向仍然在iframe内部工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已阅读了

  • developer.mozilla.org iframe

  • -

    So I've read about the HTML5 sandbox property and I understand that if I want to prevent an iframe redirect its parent window I can use the sandbox property leaving allow-top-navigation out. However when this is done, if the iframe was originally relying on top level redirection, what happens in its place is that it redirects to a blank page, effectively breaking navigation.

    Can I prevent the iframe from tinkering its parent window while still allowing "top level" redirects, only letting these work within the context of the iframe instead of being top level?

    Edit: For context, I'm working with a third party and its page has a form with a target _top. If the iframe is sandboxed, upon submitting the form users get a blank page, if it's not sandboxed the entire page is redirected. I'm looking for something that would allow to submit the form and show the result within the iframe itself.

    解决方案

    With HTML5 the iframe sandbox attribute was added.

    At the time of writing this works on Chrome, Safari, Firefox and recent versions of IE and Opera but does pretty much what you want:

    Allows the iframe content to be treated as being from the same origin as the containing document

    <iframe src="url" sandbox="allow-same-origin"></iframe>
    


    Browser Compatibility


    Some Useful links

    这篇关于有没有一种方法可以防止iframe重定向父窗口,但是以这样的方式,即“顶级”重定向仍然在iframe内部工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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