How to code url that on load opens two tabs without user interaction required?

Viewed 98

I need to code a url that when somebody visits, it automatically opens two new tabs with the urls I want.

so when somebody goes to http://www.myurl.com (just code here, no content), JQuery

two tabs(in the order that I choose) will be open for the user, for example:

1st) https://www.destinationurl1.com 2nd) https://www.destinationurl2.com

I have read some information and other questions where it seems that this kind of behaviour is often blocked(by Chrome mostly) unless the opening of the new tabs comes from a user's physical action, such as after a button click

I am looking at a way to acomplish this without any user interaction required other than going to http://www.myurl.com and without the user seeing anything other than the two new tabs opening.

Not sure if html, javascript, Ajax, PHP or a mix of any of these could be used.

Thank you for any guidance!

2 Answers

Edit

The solution I found working (Though the user needs to disable popup-blocking on "smart" browsers) is by using window.open(document.getElementById('urlToClick').href);

as used in here: http://jsfiddle.net/fLLrs/1171/

There's just about no JQuery remaining in the fiddle except the jQuery(window).load(()=>{...})

Once more to reiterate: It works but the user needs to enable popups!

original

If you're using JQuery you could try it by using two elements like this on your page (no text so they don't render anything).

<a href='dest1' id='url1' target='_blank'></a>
<a href='dest2' id='url2' target='_blank'></a>

and then using

$("url1").click();
$("url2").click();

I've used this previously in some of my user scripts, though not in any which are supposed to automatically do stuff without user-interaction.

you can do it simply ike below,

$(document).ready(function(){
    window.open(
      'https://www.destinationurl1.com/',
      '_blank' // <- This is what makes it open in a new window.
    );
    window.open(
      'https://www.destinationurl2.com/',
      '_blank' // <- This is what makes it open in a new window.
    );
});
Related