我正在使用我想使用自己的 css 设置样式的外部 iframe。iframe 由 javascript 加载和创建,女巫本身由另一个 javascript 加载。由于这是一家公司提供的服务,我无法控制他们的 javascript 生成的内容或 iframe 内容。
到目前为止,我使用 jquery 所做的是使用 window-onload 将我所有的自定义 css 文件加载到 iframe 中,如下所示:
window.onload = function() {
$('iframe').addClass('styledIframe');
var $c = $('.styledIframe').contents();
//clone all styles from this document into the iframe
$c.find('head').append($('style, link[rel=stylesheet]').clone());
}
iframe 每次加载时都会更改 ID,因此我添加了“styledIframe”类。对于我的问题:这在除 Internet Explorer 之外的所有浏览器中都能完美运行,我在 IE9 及更低版本中进行了尝试,但在任何浏览器中都不起作用。
我该怎么做才能在 IE 中完成这项工作?