如何让allow-scripts和allow-same-origin在iframe中共存?

Mar*_*der 7 html iframe sandbox firefox-addon firefox-addon-webextensions

所以我只想在 iframe 中沙箱一个 html 文件,只要有allow-scripts属性它就可以工作,但只要我添加allow-same-origin它就停止工作,因为:

\n\n
\n

有关沙箱的注意事项:\n 当嵌入文档与嵌入页面具有相同来源时,强烈建议不要同时使用allowed-scriptsallowed-same-origin因为这会让嵌入文档删除沙箱属性\xe2\x80 \x94 使其并不比根本不使用沙箱属性更安全。\n 如果攻击者可以在沙箱 iframe \xe2\x80\x94 之外显示内容(例如查看者在新选项卡中打开该框架),则沙箱是无用的。此类内容还应从单独的源提供,以限制潜在的损害。\n Internet Explorer 9 及更早版本不支持沙箱属性。来自:
\n https://developer.mozilla.org/en-US/docs/Web /HTML/元素/iframe

\n
\n\n

iframe代码:

\n\n
<iframe src="index.html" sandbox=\'allow-scripts allow-same-origin\'></frame>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想要,allow-same-origin因为我想在 iframe 中使用与 index.html 中相同的 css。

\n

tec*_*yg5 4

将 iframe 内容托管在与父页面不同的源(即不同的域或子域)上。这将在使用时保证 iframe 的安全sandbox="allow-scripts allow-same-origin"

但无论哪种方式,CSS 都不会在 iframe 中继承。事实上,这就是 iframe 的全部目的。即使没有allow-same-origin设置,您也可以在两个页面中加载相同的 CSS 文件。