Remove an iframe element

Asked

Viewed 683 times

0

Good morning, I am trying to remove an element that is inside an iframe, I am even trying to add a class via jquery but without success, I have tried to use jQuery load, setTimeout and onload by calling a callback but without success.

Someone has a solution to help me.

Note: Pass any console command in the development tool, it works.

Iframe

<iframe id="frame" onload="callback(this)" src="{URL}" width="100%" height="100%"></iframe>

jQuery

<script type="text/javascript">
    function callback() {
        alert('Carregado');
        $('#elementoParaRemover').remove();
    };
</script>

1 answer

0

Friend you can use the jquery remove:

$("#idFrame").contents().find("#element").remove();

I hope I’ve helped.

  • So I tried that way too, but it still doesn’t work. The problem is that it doesn’t run anything inside the iframe. Ex: addClass(), remove(), html(), etc... still, thanks for trying to help.

  • What error is giving friend? It is in relation to origin or Cors?

  • Error showing on console. failed to read the 'contentDocument' Property from 'Htmliframeelement': Blocked a frame with origin "SITE" from accessing a cross-origin frame.

  • The problem is that Cors is blocking access to the element. Take a look at this topic the guy teaches you how to disable this: https://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame

Browser other questions tagged

You are not signed in. Login or sign up in order to post.