【问题标题】:Cant add stylesheets to iframe in internet explorer无法在 Internet Explorer 中将样式表添加到 iframe
【发布时间】:2013-05-29 10:10:27
【问题描述】:

我正在使用我想使用自己的 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 中完成这项工作?

【问题讨论】:

标签: jquery css internet-explorer iframe


【解决方案1】:

您不能为 iFrame 中的元素设置样式,因为从技术上讲,它们不存在于页面上,但存在于另一台服务器上。但是,如果 iFrame 来自同一服务器,您可以设置样式 - 这是一个安全问题。 我知道第三方的噩梦,但就是这样。您只能要求他们在他们的服务器上安装您的样式,或者要求他们自己更改内容的样式以适合您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 2012-08-19
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    相关资源
    最近更新 更多