Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open specific link in new tab on pageload

Previously, I got a solution from here on how to open another link automatically on page load. I got this code to do that

window.setTimeout("autoClick()", 2000); // 2 seconds delay

function autoClick() {
var linkPage = document.getElementById('dynLink').href;
window.location.href = linkPage;
}
</script> 

dynLink is used in the body as target="_blank" within link tag. But this is loading the desired page within the same tab. Not in a New Tab.

I want when this auto page load clicks the link with id=dynLink, the page opens in a new tab then to load in the same tab.

And I really means New TAB - NOT NEW WINDOW.

Looking forward to some working solution. Thanks!

like image 269
Suman Armaan Avatar asked Mar 14 '23 20:03

Suman Armaan


1 Answers

Following are some of the solutions using plain HTML and JavaScript. You may use based on your requirement and share if you have any other solution.

Open Link Immediately on Page Load.

<body onload="window.open('https://www.google.com/');">

Open link in New Tab on page load.

<body onload="window.open('https://www.google.com/', '_blank');">

Refresh the same URL Using meta tags.

<meta http-equiv="refresh" content="5" />

Refresh a different URL after 5 seconds Using meta tags.

<meta http-equiv="refresh" content="5;URL='https://www.google.com/'" />

Open different URL in New Tab using meta tags.

<meta http-equiv="refresh" content="5;URL=javascript:window.open('https://www.google.com/', '_blank');" />
like image 73
Aamer Shahzad Avatar answered Mar 23 '23 03:03

Aamer Shahzad