Popups are blocked by browsers when an action is identified window.open
(or equivalent) other than apparent be an immediate user action. Older browsers could consider any function stack as a bad signal and choose to block. At the present time, the process is more sophisticated and will examine with a better performance the characteristic of the call.
A practical example:
<body onload="abrir(true);">
<button id="abcd" type="button" onclick="abrir(false)">Ação Direta</button>
</body>
<script type="text/javascript">
function abrir(value) {
if (value) {
setTimeout(function () {
window.open('http://answall.com');
}, 5000);
} else {
window.open('http://answall.com');
}
}
</script>
Even if it is the same function and using Timeout to try to cheat, Google Chrome will block a pop-up after 5 seconds of page loading, however it will never block the user click.
We can simplify the function and find the same behavior:
<script type="text/javascript">
function abrir(value) {
window.open('http://answall.com');
}
</script>
What causes a popup to be blocked?
The ability of the browser to determine whether to call the function window.open
is intended by the user or not.
In theory, any page you go to, you can click to access the address, so... you can trigger the popup event at that time.
– Ivan Ferrer