What makes a popup block?

Asked

Viewed 1,501 times

6

I’ve noticed that some libraries, such as login with facebook, always use popups for user authentication and, almost always, this popup is not blocked.

Usually when it opens with a click event there are no locks. And when we use window.open directly on the console, for example, they are locked.

How to determine when the popup will be blocked?

Is there any way to circumvent this lock? Or is there any way to "inform" that such a popup is "reliable" for opening?

1 answer

7

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.