0

I know this is a newbie question but I really need help. I created a landing page required visitor to input the password to access the target page. The below code works fine but it opened a window as a popup so Chrome blocks it. How should I edit the code below to prevent that happen? Thank you so much!

<SCRIPT>
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter the Password','');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1.toLowerCase() == "letmein") {
alert('Access approved! Catalogue is now open.');
window.open('sandoz-ecatalog.html','_blank');
break;
}
testV+=1;
var pass1 =
prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return "";
}
</SCRIPT>
Awa Shuen
  • 1
  • 1
  • https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window This could solve your problem – dolor3sh4ze Jul 29 '21 at 07:56
  • Does this answer your question? [Open a URL in a new tab (and not a new window)](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window) – Timothy Alexis Vass Jul 29 '21 at 08:13

2 Answers2

0

Opening a new window without blocking it is relative to the browser user. You cannot prevent the user from blocking the opening of a new window

As the popup blocker is activated on a window.open that is not invoked by the user, I advise you to make a button or something else in order to create an interaction with the user that would not block the new popup

dolor3sh4ze
  • 925
  • 1
  • 7
  • 25
0
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter the Password','');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1.toLowerCase() == "letmein") {
alert('Access approved! Catalogue is now open.');
  window.open("", "_blank",     "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");


break;
}
testV+=1;
var pass1 =
prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return "";
}

This will work for you

Harshil Khamar
  • 186
  • 1
  • 6
  • It's working for me what you want to do is to open a pop on when password is correct right?? – Harshil Khamar Jul 29 '21 at 09:51
  • Yes, but after input the correct password, will prompt another box saying "Access approved" then user need to click OK. After click OK the popup blocker blocks it again. – Awa Shuen Jul 29 '21 at 14:30
  • If it's blocking popup then it's your browser's feature. Check in settings you had disabled popups or you can allow it when it's get blocked The javascript is working correctly there is no problem in it but if you don't wont any popup messege then you can open new page in new tab – Harshil Khamar Jul 30 '21 at 09:32