How to apply CSS to inner Iframe element through parent window CSS class?

前端 未结 2 829
旧巷少年郎
旧巷少年郎 2020-12-15 23:06

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

When I googling for it, I

2条回答
  •  旧时难觅i
    2020-12-15 23:36

    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 ,(All the iframe's domain is the same as the parent) ..

    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($('')
                );
            });
        });
    

提交回复
热议问题