Can't seem to find anyone to figure this out. Just trying to get <iframe>
BTN to talk to parent.
Simple problem, need to get a button inside an <iframe>
to call function on main.html.
The setup is as follows:
- main.html has
<iframe>
with products.php inside. - Products.php has button that loads confirmation.php
- Confirmation.php has the BUTTON we need to call function on parent.
- all files are on the same server/domain
The traditional method of button inside products.php changing src on main to confirmation.php works as expected.
The problem is happening here: On products.php the way it loads the confirmation page is with this:
private $base_url = "https://xxxxxxxx.com/";
$returnURL = $this->base_url . "confirmation.php";
Products page <form>
submission calls this PHP. This action is somehow embedding the confirmation page, or appending it in a way it can't communicate with parent.
Button & function on confirmation.php:
<button type="button" onClick="test()">BACK</button>
<script>
function test() {
parent.mainTest();
}
</script>
All of the below have been tested in confirmation page func and failed.
- parent.mainTest();
- window.parent.mainTest();
- document.parent.mainTest();
- parent.document.getElementById('iframe1_id').src = "iframeTest.php";
- window.parent.frames["iframe1"]
Script on main.html:
<script>
function test (){
alert("Worked");
}
</script>
<iframe src="products.php" id="iframe1_id" name="iframe1"></iframe>