我正在做一个项目。我面临一个问题,当用户提交他们的 ID 和密码并单击提交时,我将用户签入数据库,当它匹配时,我通过 window.open 脚本打开一个新窗口,但它总是请求浏览器的许可才能打开弹出窗口。 我只想在没有弹出浏览器权限的情况下打开新窗口
这是我的提交按钮
<input type="submit" name="submit" value="Sign In" class="login_button" style="border:none; background:none; font-size:14px; padding:0px; margin-top:5px; font-weight:bold; color:#fff" />
<?php
if($user->login == 1){
$this->loginUser($user);
?>
<script>
var h = screen.height;
var w = screen.width;
window.open("<?php echo CreateURL('index.php',"mod=guidelines"); ?>", 'newwin', 'height='+h+'px,width='+w+'px')</script>
<?php
}
else{
$error .= "You are not authorized to login. Please contact system administrator.";
}
?>
您必须启用弹出窗口,因为 window.open 会打开一个弹出窗口。
1) chrome 设置 --> 隐私 --> 内容设置检查允许 弹出窗口。 2) IE工具-->隐私-->关闭弹出窗口拦截器
希望这有帮助
<?php
if($user->login == 1){
$this->loginUser($user);
?>
<!-- USE TARGET WHAT EVER YOU WANT -->
<a target="_parent" href="<?php echo CreateURL('index.php',"mod=guidelines"); ?>" id="test-ak"> </a>
<script>
var h = screen.height;
var w = screen.width;
document.getElementById('test-ak').click(); // try something like that if you dont care about the window size
</script>
<?php
}
else{
$error .= "You are not authorized to login. Please contact system administrator.";
}
?>
如果打开弹出窗口请求不是由用户点击生成的,浏览器将始终请求浏览器允许打开弹出窗口。
因此,您有两种选择来避免此弹出窗口阻止程序。
使用同步ajax调用将用户签入数据库,并在ajax成功打开窗口弹出窗口的同一调用中。
从数据库成功检查用户后,向用户显示某种类型的对话框,并要求用户单击某个按钮,然后在该按钮上单击编写打开的窗口函数。