0

I have an application where I need to redirect to a website ( example below). My issue is that the cakephp3 application is embedded in a wordpress iframe and for some reason the below command executes inside an iframe so i have a webpage within a webpage. How can i redirect to a webpage outside an iframe?

//controller
if ....
    return  $this->redirect('http://www.xxxxxx/thank-you-application/');
jagguy
  • 183
  • 1
  • 3
  • 16
  • Why would you expect a different behavior when the website is embedded in a frame? **https://stackoverflow.com/questions/580669/redirect-parent-window-from-an-iframe-action** – ndm Aug 20 '17 at 11:37

1 Answers1

0
  • What goes on in Vegas, stays in Vegas
  • What goes on in an iframe, stays in that iframe

I don't think what you want is possible with PHP (and any PHP framework), Maybe with getting the content of the page that you want to load inside the iframe with:

$http = new Client();
$response = $http->get('http://example.com');
$content = $response->body();

and put the $content in the view in the "top level page / mean not inside iframe" (like they do in financial website), but i'm not sure of the exact way.

the easiest solution is to send in your controller a value ($redirect = true) to the view that will say: "Hey! view, plz open this link to the top level window! / mean outside the iframe".

write something like this in your view (or template):

<!-- ... -->
 <?php if($redirect) : ?> 
 <body onload="javascript:window.top.location.href='<?= $this->Url->build([
    "controller" => "Pages",
    "action" => "display",
    "thank-you"
     ]) ?>'";>
<?php else: ?>
<body>
<?php endif; ?>
<!-- ... -->

Hope it helps

Benfarhat
  • 183
  • 7