Modify css of element within iframe

2

I have an iframe with id="myframe" that has another source file from the same server

<iframe id="myframe" src="referencia.php">

</iframe>

In reference.php I have a div with id="box" that I want that when it opens directly the php reference file is visible, but that "myframe" does not appear. I have tried with jquery the following but it has not worked for me

$('#myframe').$('#cuadro').css({'display':'none'});

or

$('#myframe').contains('#cuadro').css({'display':'none'});
    
asked by Luis Carlos Gallegos 10.03.2018 в 18:14
source

1 answer

3

Si está dentro del mismo servidor one way to do this would be to add tag to body of the document or page that loads in iframe with the respective css rules that you want for this case the display: none for div with id #cuadro . If it is an external page, it can not be done because this protects you from the typical attacks Cross-site scripting (XSS)

Remember to access the content with contents , then search (find) for the head element, then add the style tag

$('#myframe').contents().find("head")
   .append($("<style type='text/css'>  #cuadro{display:none;}  </style>"));
    
answered by 10.03.2018 в 18:45