I have this JS code:
window.open(loginurl, '_blank');
coming from a condition for example:
if (userloggedin) {
//popup another page
} else {
window.open(loginurl, '_blank');
}
“loginurl” is an login URL that I would like to open in new window.
Problem: This will be blocked in most browsers (Firefox and Chrome) because it behaves like a popup.
I would like a solution that will still utilizes my login URL variable (not altering the if else statement), open it in new window without any warnings of a popup that is being blocked.
I am searching for ways but I never found a solution. If somebody can provide some tips or insights. That would be highly appreciated.
Thanks.
The window opened by
window.openwill always be regarded as a pop-up to block by browsers when the function is triggered without a user action initiating it.That means that for example that these will not be blocked:
Chrome even allows other events to trigger the popup, while firefox will not allow this:
And this will be blocked:
So, unless you’re triggering the
window.openafter a user action, you can never be sure that your window won’t be blocked.