我的 Controller 上有我的 PHP 代码,并且有一个弹出窗口和之后 完成弹出窗口的功能我想关闭我的弹出窗口并 wan 重定向到相应的页面。我如何使用 PHP 来实现这一点。我 尝试使用以下代码,但它不起作用
$strRedirectUrl = $this->m_strSecureBaseName . 'Apartments/module/application_application_list/action/view_application_list/'; echo '<script type="text/javascript">
window.opener.location.replace(' . $strRedirectUrl . ');
window.close; <script>';
请帮助我。
谢谢
最佳答案
在弹出页面中调用这个JS:
window.opener.location.href = "http://some/new/location";
window.close();
PHP 代码
echo"<script language='javascript'>";
echo("window.opener.location.href = '" . $strRedirectUrl . "';");
echo("window.close();");
echo "</script>";
演示:
第 1 页 文件:page_1.php
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
</head>
<body>
<a href="JavaScript:newPopup('page_2.php');">Open a popup window</a>
</body>
</html>
第 2 页: 文件:page_2.php
<?php
$strRedirectUrl = "page_1.php";
echo"<script language='javascript'>";
echo("window.opener.location.href = '" . $strRedirectUrl . "';");
echo("window.close();");
echo "</script>";
?>
新编辑的代码
PHP 代码
if (success condtion) {
$strRedirectUrl = "page_1.php";
echo"<script language='javascript'>";
echo("window.opener.location.href = '" . $strRedirectUrl . "';");
echo("window.close();");
echo "</script>";
}
else
{
echo json_encode(array(
'status' => 'error',
'message'=> 'error message'
));
}
Jquery 代码
$.ajax({
type: "post",
url: "postride.php",
dataType:"json",
success: function (response) {
if(response.status === "error") {
// do something with response.message or whatever other data on error
} else {
return false;
}
}
});
关于php - 想要在 Controller 上执行 PHP 脚本后关闭弹出窗口并重定向到相应页面而不发生任何事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18670013/