如何强制iFrame打开所有链接保留在iFrame中? [英] How force iFrame open all links stay in the iFrame?

查看:124
本文介绍了如何强制iFrame打开所有链接保留在iFrame中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我托管一个iFrame,它看起来像一个链接指向外部域时,它将它加载到主窗口而不是iFrame中。
有没有办法强制链接在同一个iframe中打开?

I'm hosting an iFrame and it seems like when a link points to external domains it loads it on the main window and not in the iFrame. Is there a way to force the links to be opened in the same iFrame?

注意:我可以添加任何我想要加载到iFrame中的页面(使用Chrome扩展程序)。

Notice: I can add anything I want to the page loaded in the iFrame (using Chrome extension).

我尝试添加:

I tried adding:

<base target="_parent" />

但它没有做任何好处...

But it didn't do any good...

推荐答案

检查外部域名页面的标题。如果 X-Frame-Options Header设置为 DENY ,浏览器会忽略将内容加载到 iframe 框架集并加载到浏览器的主框架中。

Check Headers of your external domain page. If X-Frame-Options Header is set to DENY, browser ignores loading content to iframe or frame set and loads in main frame of browser.

Regardless of the site attempts the page cannot be displayed in a frame.



您的代码



< base target =_ parent/> 用于将结果加载到当前父浏览上下文中。如果没有父项,该选项的行为方式与 _self 相同,因此它不能解决您的问题。

Your Code

<base target="_parent" /> is used for Loading the result into the parent browsing context of the current one. If there is no parent, this option behaves the same way as _self, so it can not solve your problem

使用
< base target =myframe> 代替,其中 myframe 是iframe的名称。

Use <base target="myframe"> instead where myframe is name of your iframe.

<iframe width="200" height="200" name="myframe"></iframe>



演示



查找服务器标题加载页面

Demonstration

Look for server headers for loading pages

<html>

    <head>
        <base target="myframe">
    </head>

    <body>
        <a href="hi.html">Base</a>
        <a href="bye.html">A Tag</a>
        <iframe width="200" height="200" name="myframe"></iframe>
    </body>

</html>



参考文献




  • X-Frame-Options Header
  • >

    References

    • X-Frame-Options Header
    • 这篇关于如何强制iFrame打开所有链接保留在iFrame中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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