Thursday, March 22, 2012

Closing the PopUp and redirecting Parent Window

I have tried for few hours to solve this problem Here is the simple example which helps you to solve the Problem

Problem:
 Create a PopUp window on submission of a value in PopUp the PopUp Closes and the Parent Windows redirects to Some other Page 

Solution:
Here is the simple way to solve it

Create 2 php pages

1. popup.php
Copy this Code

<html>
    <head>    
    </head>
    <body>
        <a href="#" onclick="window.open('popupcode.php','Login','height=500,width=420,scrollbars=yes');return false;">PopUp</a>
    </body>
    </html>




Now Create page : popupcode.php


Copy this code:


<?php
if (isset($_POST['butSubmit']) && '' != $_POST['butSubmit']) {
    $strValue = $_POST['text'];
    if ('abc' == $strValue) {
        ?><script>
             
                   opener.location.href = 'http://localhost/changerepublic/';
                   window.close();
        </script>
        <?php
    }
}
?>
<form name="" method ="POST">
    <input type='text' name = 'text'/><input type = 'submit' name= 'butSubmit' value ="OK"/>
</FORM>


Now run popup.php So i hope this code might give you an basic idea of how to open a POPUP and redirect the parent window by closing the PopUp