简体   繁体   English

无法在Internet Explorer中将样式表添加到iframe

[英]Cant add stylesheets to iframe in internet explorer

Im working with an external iframe that I want to style using my own css. 我正在使用要使用自己的CSS设置样式的外部iframe。 The iframe is loaded and created by a javascript witch itself is loaded by another javascript. iframe是由javascript加载和创建的,巫婆本身是由另一个javascript加载的。 Since this is a service provided by a company i have no control over what their javascript produces or the iframe content. 由于这是公司提供的服务,因此我无法控制其javascript产生的内容或iframe内容。

What I have done so far using jquery is to load all of my custom css files into the iframe using window-onload like this: 到目前为止,我使用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());
}

The iframe changes the ID everytime its loaded so that why i added the class "styledIframe". iframe每次加载时都会更改ID,因此,为什么要添加类“ styledIframe”。 To my problem: this works perfect in all browsers exept Internet explorer, i tried it out in IE9 and lower and it doesn't work in any of them. 对我的问题:在Internet Explorer以外的所有浏览器中,此功能都非常完美,我在IE9及更低版本中进行了尝试,但不适用于其中的任何一种。

What can I do to make this work in IE? 我该怎么做才能在IE中完成这项工作?

You can not style elements from an iFrame as technically they don't exist on the page but exist on another server. 您无法为iFrame中的元素设置样式,因为从技术上讲,它们在页面上不存在,但在另一台服务器上存在。 You can however style if the iFrame comes from the same server - its a security issue. 但是,如果iFrame来自同一服务器,则可以设置样式-这是安全问题。 3rd party nightmares I know but that's the way it is. 我知道第三次派对的噩梦,但事实就是这样。 You can only ask them to install your style on their server or ask them to change the styling of the content themselves to suit you. 您只能要求他们在他们的服务器上安装样式,或要求他们更改内容的样式以适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM