如何强制iFrame 打开所有链接都留在iFrame 中?

Guy*_*and 4 iframe google-chrome-extension

我正在托管一个 iFrame,似乎当一个链接指向外部域时,它会在主窗口而不是 iFrame 中加载它。有没有办法强制在同一个 iFrame 中打开链接?

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

我尝试添加:

<base target="_parent" />
Run Code Online (Sandbox Code Playgroud)

但这没有任何好处......

Sud*_*han 5

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

Regardless of the site attempts the page cannot be displayed in a frame.
Run Code Online (Sandbox Code Playgroud)

你的代码

<base target="_parent" /> 用于将结果加载到当前浏览器的父浏览上下文中。如果没有父级,则此选项的行为与 相同_self,因此无法解决您的问题

<base target="myframe">改用myframe您的 iframe 的名称在哪里。

<iframe width="200" height="200" name="myframe"></iframe>
Run Code Online (Sandbox Code Playgroud)

示范

查找用于加载页面的服务器标头

<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>
Run Code Online (Sandbox Code Playgroud)

参考