【问题标题】:Creating iFrame with content cross origin [duplicate]使用内容跨源创建 iFrame [重复]
【发布时间】:2018-12-26 05:05:10
【问题描述】:

我正在尝试创建一个空的 iframe,用一些 html 代码填充它(这里:“Hello World”) 使用 JavaScript。 该脚本文件托管在域a.com 并从位于b.net 的网站加载。

所有其他 js 代码都可以工作,但是当我尝试设置 iframe 的内容时,我得到一个跨源错误。 有合适的解决方法吗?

var node = document.createElement("iframe");
node.setAttribute("border", "0px");
node.setAttribute("sandbox", "");
node.setAttribute("id", "preload");
var obj = document.getElementsByTagName("footer")[0].appendChild(node);
node.contentWindow.document.open();
node.contentWindow.document.write("Hello World");
node.contentWindow.document.close();

【问题讨论】:

  • 我不想获取内容,我想设置内容。所以刚刚创建的 iFrame 没有内容...
  • 但这真的是跨域吗?既然 iFrame 确实没有 src 属性,那它怎么会有来源呢?
  • @VDWWD 如果问题是重复的,为什么删除“沙盒”然后解决问题?实际上,跨源错误只是误导......

标签: javascript iframe xss


【解决方案1】:

“沙盒”似乎确实阻止了对文档的访问。删除“沙盒”解决了这个问题。

【讨论】:

    猜你喜欢
    • 2020-08-20
    • 2011-12-17
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 2014-03-02
    相关资源
    最近更新 更多