iframe content with style in head with hex color code not working

落花浮王杯 提交于 2020-01-15 03:16:06

问题


I am generating iframe using javascript with dynamic html. My dynamic html looks like-

<head>
<style>
...
.bar {background-color: #EB593C;}
...
</style>
</head>

Then iframe contents all code till .bar {background-color: after color code html/css is not included in iframes contents.

If I replace hex color code with rgb or text color name then that is working fine.

But as I said html is dynamic so I cant replace all the hex color codes to to rgb or text.

var iframe = document.createElement('iframe');
//var html = '<style>body {background-color: #EB593C;}</style><body>Foo</body>'; // not working
var html = '<style>body {background-color: red;}</style><body>Foo</body>'; // working
iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(html);
document.body.appendChild(iframe);

Please check jsfiddle

|improve this question

来源:https://stackoverflow.com/questions/37437019/iframe-content-with-style-in-head-with-hex-color-code-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!