Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

javascript - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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');" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...