1

コントローラーに PHP コードがあり、ポップアップが 1 つあり、ポップアップの機能を終了した後、ポップアップを閉じて、それぞれのページにリダイレクトしたいと考えています。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>';

私を助けてください。

ありがとう

4

1 に答える 1

0

ポップアップ ページでこの 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'
));
}

Jクエリコード

     $.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;
            }
        }
    });
于 2013-09-07T05:32:19.953 に答える