vitbits
vitbits

Reputation: 25

Going to two URLs in html

On begin.html, I've written some code like:

<a target="_blank" href="test.php">Proceed</a>;

This makes the link open in a new tab/window. Simultaneously, I want to go to test2.php from begin.html by clicking on the same link. So, basically, at the end of my operation, one tab shows test2.php and the new tab shows test.php. Is it possible?

Upvotes: 1

Views: 147

Answers (2)

bfontaine
bfontaine

Reputation: 19831

You need JavaScript to do that; and even with it it’s very likely the browser will block the second window thinking it’s a popup:

<button id="b">Click here</button>

 

document.getElementById("b").addEventListener("click", function() {

    window.open("https://www.google.com", "_blank");
    window.open("https://www.bing.com", "_blank");

}, false);

See this JSFiddle.

Upvotes: 1

Shuvro
Shuvro

Reputation: 1499

Considering you have test2.php in root folder as test.php. you can try it this way. Don't forget to add your javascript code inside a script tag.

<script>
function OpenNewPage() {
  var win = window.open('test2.php', '_blank');
  win.focus();
}
</script>

<a target="_blank" href="test.php" onclick="OpenNewPage();">Proceed</a>

Upvotes: 1

Related Questions