【发布时间】:2016-08-12 15:26:21
【问题描述】:
我正在尝试打开一个新的 html 窗口并将其链接到外部 css 文件..
var myWindow = window.open("", "MsgWindow");
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", 'kamusi_ext-v1.css');
myWindow.document.head.appendChild(fileref);
但是我得到了这个错误:
script.js:70 Uncaught SecurityError: Blocked a frame with origin "null" from access a frame with origin "null".协议、域和端口必须匹配。
在 Firefox 上运行相同的脚本时,我没有收到此错误,但没有应用 css!
【问题讨论】:
-
建议使用postMessage,这是一个安全问题,你的方式肯定不会跨浏览器,参考developer.mozilla.org/en-US/docs/Web/API/Window/postMessage,你可以发布你的风格uri并附加在receive中
标签: javascript jquery html css w3c