Open multiple tabs on a Javascript link

Asked

Viewed 2,643 times

0

This script is to open two tabs or more in the browser on a single link. Clicking on the link opens only a new tab and the other is blocked as pop-ups by the browser. How do I not block? Or there is another way to open multiple tabs on a single link?

<script language="JavaScript">
  function teste() {
    window.open("www.google.com", "_blank");
    window.open("www.gmail.com.br", "_blank");
}
</script>

<a href="javascript:teste();">Clique aqui para abrir as abas</a>
  • This question has already been answered here in the community. I did a quick search in the Stackoverflow directory and managed to find the answer. Work out.

  • #vdschuck Fixed the code was wrong, I tested this right, and try the code.

1 answer

1

It is no longer possible to do this in recent browsers or containing popup blocker, so if window.open(...) do not return an object or return undefined or null, you can know if the same popup has been blocked, but still will not be able to open multiple tabs at the same time while your code block is not running.

if (!window.open("www.google.com", "_blank")) {
    /* Popup bloqueado. O que fazer? */
}

I think it’s best not to try to open several tabs at the same time.

  • 1

    only by study: there are some solutions around this, namely simulate a user-made click ;)

  • @Moshmage IE, will need the user to manually click. Anyway I know almost nothing about these native windows

  • no, you just need to get Pointer to move and click the button as a user would normally

  • @Moshmage No, the browser does not expose any possibility of moving the cursor, and HTMLElement#click is blocked by default (I’ve never tested this method along with popups actually, but I’ve tested with requestFullscreen)

  • an answer in SO-EN; also, open the console and give it document.querySelector('.comment-help-link').click() Check if the help of the comments does not open. (ps, obviously, the window has open q tar)

  • @Moshmage I’ve already talked about the method HTMLElement#click, see my comment above. But I will test the answer to that question later because my mother goes to church

Show 1 more comment

Browser other questions tagged

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