0

Sorry, if it is obvious for you. I'm new in JavaScript.

I have written a script within a PHP and the page wants user a password to open a new window.

If the password is wrong or if it is null, it will give a specific error inside the current page by going to another url. but if the condition is satisfied, it will open a new page.

The problem is that I don't know how to close the former page automatically.

Here is my code:

<?php
$var1="1";
$pass=$_POST['password'];
if ($pass==$var1) 
{ ?>
<script>
window.open('1.html');
</script>
<?php
}
elseif ($pass=="")
{header("location:null.html");}

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

?>

Thank you

Nima
  • 191
  • 2
  • 3
  • 17
  • What's wrong with the existing window? – Quentin Nov 24 '13 at 21:46
  • If you're going to close the current page afterwards, why not just go to the other page instead of opening a window and then closing the old one? – markasoftware Nov 24 '13 at 21:50
  • there is nothing wrong with it . I can give it a url like two other conditions with php but I want it to be closed. I think the link you offered me , solves the problem. thnaks – Nima Nov 24 '13 at 21:52
  • @ markasoftware because the size of the current page is too small (just a small password field ) and the user has to make that bigger by hand – Nima Nov 24 '13 at 21:57

1 Answers1

1

This could help: https://stackoverflow.com/a/8890426/3021964

Should work, since you've opened the window with window.open('1.html').

Community
  • 1
  • 1
Anthronaut
  • 83
  • 1
  • 11