0

i have a website that contain an iframe. www.vendeposto.com.br and i want to hide an element <div class="col-sm-12 col-md-4 col-lg-3">

Im trying to do this:

<script>
function myFunction() {
  var iframe = document.getElementById("myFrame");
  var elmnt = iframe.contentWindow.document.getElementsByTagName("col-sm-12 col-md-4 col-lg-3")[0];
  elmnt.style.display = "none";
}
</script>

The index.html of the vendeposto.com.br site is this:

        <!DOCTYPE html>
    <html>
    <head>
    <title>Postos de gasolina a venda</title>
    <meta name"author" content="Vinicius Boscolo">
    <meta name="description" content="Compra e venda de postos de combustíveis e lojas de conveniência"
    <meta name="keywords" content="postos, postos de combustivel, posto de copmbustivel, posto, posto a venda, postos a venda, posto de gasolina, postos de gasolina, posto de combustivl a venda, postos de combustivel a venda, posto de gasolina a venda, postos de gasolina a venda">
    </head>
    <body>
    <iframe id="myFrame" src="https://www.alugai.com.br/imoveis?codigo=PT0002%2C+PT0003%2C+PT0004%2C+PT0005%2C+PT0006%2C+PT0007%2C+PT0008%2C+PT0009%2C+PT0010" style="position: absolute; height: 100%; width: 100%; border: none"></iframe>

<script>
function myFunction5() {
  var iframe = document.getElementById("myFrame");
  var elmnt = iframe.contentWindow.document.getElementsByTagName("col-sm-12 col-md-4 col-lg-3")[0];
  elmnt.style.display = "none";
}
myFunction5();
</script>

    </body>
    </html>

but thats now working, the element stills there. And id like to change the logo too, but i dont know how to do that inside an iframe.

Anybody can help me?

  • Possible duplicate of [How to change style of iframe content cross-domain?](https://stackoverflow.com/questions/4724904/how-to-change-style-of-iframe-content-cross-domain) – Mark Schultheiss Mar 22 '19 at 15:03
  • https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy has some details on exceptions – Mark Schultheiss Mar 22 '19 at 15:07

3 Answers3

2

You cannot edit iframe with another domain, its restricted by cross-domain policy.

user3804427
  • 432
  • 2
  • 12
  • Hum got it... the other domain is mine too. So is there anyway to do that in the html of the alugai.com.br. Any code that check if the site is accessed by the domain vendeposto.com.br and if that’s true hide that element? – Vinicius Boscolo Mar 22 '19 at 16:50
0

You're doing your query against a class name, but you're looking for tag name:

var elmnt = iframe.contentWindow.document.getElementsByTagName("col-sm-12 col-md-4 col-lg-3")[0];

Should be:

var elmnt = iframe.contentWindow.document.getElementsByClassName("col-sm-12 col-md-4 col-lg-3")[0];
Jeremy Corbello
  • 150
  • 2
  • 9
0

Its not possible to communicate if is not same domain. But if both domains is yours, you can use cross-domain messaging, also you can check this example: Two way iframe communication

user3804427
  • 432
  • 2
  • 12