Question

I created a script that submits a form to an iFrame (download.php):

<?php 
//Download.php
echo '<form id="secret" action="http://location.com" target="hidden" method="post">
<!--- There are some input hiddens -->
</form>';
echo '<iframe name="hidden"></iframe>';
echo "<script>
     window.onload = function() {
         secretsend();
         var form = document.getElementById('secret');
         form.onsubmit = function() {
              alert('TEST2');
         }
     }


     function parentsub() 
     {
         parent.document.getElementById('google').submit();
     }
     function secretsend() 
     {
         alert('TEST');
         document.getElementById('secret').submit();
     }
</script>";
?>

That works, but when secretsend() is loaded the form submits it to the main page (that is an iFrame, as I said before) and not to hidden iFrame, (the initial form changes its src to http://location.com/, the action url of the form)... How can I solve that issue?

I need that for call another function called parentsub() but if the main content is replaced is impossible that anything can be called.

Was it helpful?

Solution

Try using This code.

echo '<form id="secret" action="http://location.com" target="_self" method="post">

Target: _self attribute opens the linked document in same frame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top