对不起,如果对你来说很明显。我是JavaScript的新手。
我在PHP中编写了一个脚本,页面需要用户密码才能打开一个新窗口。
如果密码错误或者为空,则会通过转到另一个网址在当前页面内发出特定错误。 但如果条件满足,它将打开一个新页面。
问题是我不知道如何自动关闭以前的页面。
这是我的代码:
<?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");}
?>
谢谢
答案 0 :(得分:1)
这可能会有所帮助:https://stackoverflow.com/a/8890426/3021964
应该可行,因为您已使用window.open('1.html')
打开了窗口。