1

Trying to delete 3 elements that are inside an iframe. Function "Delete" responsible for deleting the elements called on the element body onload doesn't run.

 <html>
    <script>
        <?php 
    echo"function delete(){ 
    var elem0=document.getElementById('".$_GET['id']."').contentWindow.document.getElementById('".$id."');
    var elem1=document.getElementById('".$_GET['id']."').contentWindow.document.getElementById('".$id1."');
    var elem2=document.getElementById('".$_GET['id']."').contentWindow.document.getElementById('".$id2."');

    elem0.removeChild(elem0.childNodes[0]);
    elem1.removeChild(elem1.childNodes[0]);
    elem2.removeChild(elem2.childNodes[0]);
    }"; ?>
    </script> 

    <body onload="delete();">
        <div>
        <?php

    $page=$_GET['id'].".html";
    $id=down;
    $id1=gerar1;
    $id2=gerar; 

              echo '<iframe src="' .$page.'" id="'.$_GET['id'].'" frameBorder="0" width="70%" height="100%" align="left" scrolling="no" />';
              echo '</iframe>';
        ?>
    </div>

    <div>
    <?php
    echo'<iframe src="../../galeria/frame2_galeria.html" frameBorder="0" width="29%" height="600px" align="right" scrolling="yes" />    
    </iframe>';
        ?>
    </div>
    </body>

    </html>
Luis Luis Maia Maia
  • 681
  • 1
  • 10
  • 30

2 Answers2

2

delete() is a keyword thats why your function was not call

Use different function name instead of delete

So its Works ...!

Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
  • Just one more thing, when i delete the element the css applied to the element stays in the page, how do i delete it? Bc the function applied to the button stays. – Luis Luis Maia Maia Jun 06 '18 at 09:54
0

I think the problem is that the iframe is not loaded done.

You just need to add the onload event handler to the iframe or something like setTimeout and put delete into it:

iframe.onload = function() { delete(); };

that should work.

Terry Wei
  • 1,521
  • 8
  • 16