Remove CSS inside the iframe

1

Hello, I have a page and I'm displaying it in an iframe, I want to create it as if it were a version 2 of the page with another style, so I want to remove the css from it and add another one without having to edit the style.css file, because I also want to keep the v1 page with the same style. Help me, it's in the same domain.

    
asked by anonymous 25.04.2018 / 23:19

1 answer

0

You can access the elements of iframe by using, for example, id of iframe :

<iframe id="frame" width="500" height="200" src="pagina.php"></iframe>

<script>
    var iFrame = document.body.querySelector("#frame");

    iFrame.onload = function(){ // aguarda o iframe ser carregado
        // altera a cor do texto da #div1 dentro do iframe
        iFrame.contentWindow.document.querySelector("#div1").style.color = "red";
    }
</script>

Using iFrame.contentWindow you can access elements with querySelector or another way to select elements you want.

    
26.04.2018 / 00:50