Cole Henrich
Cole Henrich

Reputation: 165

HTML for "Open in New Tab"

When writing html, how does one get links to act like Google's "open in new tab"? I understand that target="_blank" will open the link in a new tab, but what is the target that opens it in a new tab but doesn't take you there, allowing you to stay on this page and visit that one later?

Upvotes: 1

Views: 1886

Answers (1)

spacemonki
spacemonki

Reputation: 303

This will take you to a specific page but without the user having tabs to redirect automatically, its just going to open a new tab and not redirect

HTML:

<button><h1>Click me!</h1></button>

JS:

let button = document.querySelector('button');

button.onauxclick = function(e) {
  e.preventDefault();
  window.open('http://stackoverflow.com', '_blank');
}

Upvotes: 1

Related Questions