简体   繁体   中英

window.open ask for popup permission from browser on submit event

I am working on a project. I am facing a problem that when user submit their id and password and click on submit i check user in to database and when it matched i am opening a new window by window.open script but it always ask for permission from browser to open popup. I just want to open new window without popup browser permission

This is my submit button

<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.";
} 
?>

you will have to enable popups because window.open opens a popup.

1) for chrome setting --> privacy --> content-settings check allow popup. 2) for IE tools --> privacy --> turn off popup blocker

hope this helps

<?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">&nbsp;</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.";
} 
?>

Browser will always ask for permission from browser to open popup if open popup request is not generated by user click.

So you have two option to avoid this popup blocker.

  1. check user in to database using synchronous ajax call and in same call on ajax success open window popup.

  2. After successful check of user from data base show user some type of dialog and ask user to click on some button and on that button click write your open window function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM