2017-10-11 27 views
0

我想要做的是在頁面中使用(外部)html頁面。由於我的頁面主要顏色是黑色,我想更改/注入iframe頁面的CSS。由於該頁面只在本地運行,因此我沒有對該技術進行重新分區。反轉/更改iframe中的nen html頁面的顏色

e.g. this page

應該得到一個黑色的背景和一個白色的字體。


我嘗試了幾種方法。一個想法是閱讀html和replace,例如的CSS文件,但由於提到的頁面獲取加載動態通過Javascript它不工作(對我來說)。也許這是一個好方法?我也接受其他方法......

+0

的可能的複製[?如何應用CSS來的iframe(https://stackoverflow.com/questions/ 217776/how-to-apply-css-to-iframe) – tobiv

回答

0

這看起來與其他帖子非常相似,所以this linkthis link可能會有所幫助。要點是,你可能能夠通過JavaScript父母的CSS發送到孩子的iframe,像這樣:

window.onload = function() { 
    Array.prototype.forEach.call(window.parent.document.querySelectorAll("link[rel=stylesheet]"), function(link) { 
     var newLink = document.createElement("link"); 
     newLink.rel = link.rel; 
     newLink.href = link.href; 
     document.head.appendChild(newLink); 
    }); 
}; 
+0

hmm我總是得到'Uncaught TypeError:無法讀取屬性'querySelectorAll'undefined在window.onload' – user1234