2017-10-11 126 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