【问题标题】:cant redirect outside an iframe with cakephp3无法使用 cakephp 3 在 iframe 外部重定向
【发布时间】:2026-01-23 04:50:02
【问题描述】:

我有一个需要重定向到网站的应用程序(示例如下)。我的问题是 cakephp3 应用程序嵌入在 wordpress iframe 中,由于某种原因,下面的命令在 iframe 内执行,所以我在网页中有一个网页。如何重定向到 iframe 之外的网页?

//controller
if ....
    return  $this->redirect('http://www.xxxxxx/thank-you-application/');

【问题讨论】:

标签: cakephp cakephp-3.0


【解决方案1】:
  • 在拉斯维加斯发生的事情,留在拉斯维加斯
  • iframe 中发生的事情会保留在该 iframe 中

我认为 PHP(和任何 PHP 框架)不可能实现您想要的, 也许通过获取要在 iframe 中加载的页面内容:

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

并将 $content 放在“*页面/意味着不在 iframe 内”的视图中(就像他们在金融网站中所做的那样),但我不确定确切的方式。

最简单的解决方案是在您的控制器中向视图发送一个值 ($redirect = true),该视图将显示:“嘿!视图,请打开此链接到*窗口!/意思是在 iframe 之外”。

在你的视图(或模板)中写下这样的内容:

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

希望对你有帮助

【讨论】: