2016-08-12 80 views
0

我試圖打開一個新的HTML窗口,並將其鏈接到外部CSS文件..如何將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 accessing a frame with origin "null". Protocols, domains, and ports must match.

在Firefox上運行相同的腳本時,我沒有收到此錯誤,但未應用CSS!

+0

建議使用postMessage,這是一個安全問題,你的方式肯定不會穿越大橋,請參閱https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage,你可以發佈你的風格uri並追加接收 –

回答

0

它似乎在這裏工作: enter image description here

enter image description here

我認爲這是關係到跨域的事情。谷歌搜索你提供的錯誤會給你一個提示。祝你好運!

相關問題