0

I have a page that requests a password from user, and if the condition statement is satisfied, I want the current page to be closed, and a new window be opened instead of the former page.

I had no problem with my code in my PC's localhost and it was working without any problem. But when I upload the page into my server, there is a bad problem.

It closes the current page as I want, but it doesn't open the new window.

Here is my code:

<?php
$var1="701016";
$pass=$_POST['password'];
if ($pass==$var1) 
 { ?>
<script>
window.close();
window.open("hb.html","","height=800, width=1000, left=150");

</script>
<?php
ob_start();
}
elseif ($pass=="")
{header("location:empty.html");}

else {header("location:error.html");}

?>

Problem is with lines 7, 8

For opening window new I tried this too, but it was not effective.

window.close();
myWindow = window.open("hb.html","mywindow","height=800, width=1000,left=150");

I've got so confused. Thank you.

Nima
  • 191
  • 2
  • 3
  • 17
  • 1
    did you try to simply turn opening and closing arround ? window.open("hb.html","","height=800, width=1000, left=150");window.close(); – john Smith Jan 03 '14 at 21:01
  • yes , it's not working too :( – Nima Jan 03 '14 at 21:04
  • It's because your new page is blocked by pop-up blocker and when you close current page you loose reference to blocked page. – Givi Jan 03 '14 at 21:30
  • thanks Givi. what do you offer me to do ? – Nima Jan 03 '14 at 21:36
  • 1
    Look at [Is it possible to have event-based communication between browser windows?](http://stackoverflow.com/questions/14735706/is-it-possible-to-have-event-based-communication-between-browser-windows/14792159#14792159) and [window.open MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window.open) – Givi Jan 03 '14 at 21:41

1 Answers1

0

Turn it around.

window.open("hb.html","","height=800, width=1000, left=150");  
window.close();
user3152069
  • 408
  • 3
  • 9