0

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>
NewCodeMan
  • 227
  • 4
  • 16
  • Are the two pages (parent and iframe) on the same domain using the same protocol? – Patrick Q Aug 29 '17 at 15:40
  • Yes, sorry I will add that to post – NewCodeMan Aug 29 '17 at 16:03
  • Maybe check [this answer](https://stackoverflow.com/a/7360425/1505169) – Patrick Q Aug 29 '17 at 16:09
  • But know that you are asking that. What happens is the products page calls a separate doc payflow.php . On that page is the php that adds confirmation page. Now it sends that to - private $endpoint = "https://payflowpro.paypal.com"; and they send the reply back. Don't know if that matters. Purpose is PayPal maintains security by not sending info dir to my server, it flows to them directly. But the confirmation, products, and payflow pages are all on my server in the same folder. – NewCodeMan Aug 29 '17 at 16:09
  • 1
    It is of course not PHP, that is "breaking" things here ... I suspect it is actually the redirect back from another domain (some kind of payment gateway or similar, I assume?) ... pretty sure that a similar policy is at work here as with popup windows and the `opener` property - you lose access to that as well after an external redirect, https://stackoverflow.com/questions/7120534/window-opener-is-null-after-redirect – CBroe Aug 29 '17 at 16:10
  • If there's more going on here, you should add the relevant code to the question – Patrick Q Aug 29 '17 at 16:12
  • Thats pretty much all the relevant code. I will change title a bit. You must be right. I just dont understand why it would matter. Even though the response from paypal is telling my page what to do. The confirmation doc still exist inside my folder. I would think structure would be the same. What exactly does $returnURL = $this->base_url . "confirmation.php"; do? I thought it was just adding to the end? – NewCodeMan Aug 29 '17 at 16:19

0 Answers0