如何通过父窗口CSS类将CSS应用于内部Iframe元素? [英] How to apply CSS to inner Iframe element through parent window CSS class?

查看:477
本文介绍了如何通过父窗口CSS类将CSS应用于内部Iframe元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父(主)页面,其中有一些 iframe 部分。我想将css样式应用于内部 iframe 元素。

I have a parent(main) page that has some iframe sections. And I want to apply css style to inner iframe element.

当我在谷歌搜索时,我发现很多帖子与此主题相关但他们都建议使用jquery / javascript将CSS应用于内部元素。

When I googling for it, I found many post relate to this topic but they all suggest to use jquery/javascript to apply CSS to inner elements.

是否可以将css样式应用于内部 iframe 元素通过父窗口(主页)CSS类?

Is it possible to apply css style to inner iframe element through parent window(main page) CSS class?

(所有 iframe 的域名与父母相同)

(All the iframe's domain is the same as the parent)

推荐答案

您不能通过父窗口CSS类直接将样式应用于内部IFrame元素,即使其域与父级相同。

You can not directly apply styles to the inner IFrame element through parent window CSS class even though its domain is same as parent.

As,(所有iframe的域名都与父母一样)..

As ,(All the iframe's domain is the same as the parent) ..

你能做的最好的事情是的,使用javascript或jquery将主样式表添加到IFrame。

Best thing you can do is ,to add your main style sheet to the IFrame using javascript or jquery.

 $(document).ready(function(){
        $('#myIframe').load(function(){
            $('#myIframe')
                    .contents().find("body")
                    .html("test iframe");
            $('#myIframe')
                .contents().find("head")
                .append($('<link rel="stylesheet" type="text/css" href="style.css">')
            );
        });
    });

这篇关于如何通过父窗口CSS类将CSS应用于内部Iframe元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆