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?
Asked
Active
Viewed 993 times
1

Cole Henrich
- 155
- 3
- 17
-
2Does this answer your question? [How to stay on current window when the link opens in new tab?](https://stackoverflow.com/questions/7522565/how-to-stay-on-current-window-when-the-link-opens-in-new-tab) – Liftoff Apr 13 '21 at 21:52
-
@David, thanks for your response. No - I don't think it answers this question. As Levite helpfully observed, "Not a joke, there are just (at least) 2 different interpretations to the question (and since this was accepted, alex's interpretation was surely not be completely off). interpretation1: Open link in new tab, but leave the focus on the page the user was on. interpretation2: Open the link in the current tab, when clicked (even though it has target set to _blank) - which is correctly answered here". – Cole Henrich Apr 13 '21 at 22:02
-
@David, That question seems to be focused on the (IMO very odd) request to click a link but not actually visit it, which (absurdly) the user found to be accomplished by using some parser to remove the target aspect of the code. In sum, it was more about circumventing undesired browser behavior. What I was wondering here is sort of a simple one-liner answer (not to be picky, I appreciate anything), but if there were to be an answer, it would be like ' target="_..." is what you need'. If there's no html for that, oh well, I'll poke around for how people do it. – Cole Henrich Apr 13 '21 at 22:03
-
1Opening pop-under tabs and windows is the browser's control. – Spectric Apr 13 '21 at 22:19
1 Answers
1
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');
}

spacemonki
- 291
- 2
- 13
-
I think you know what I'm looking for. I tested it out, though, and it still sent to a new tab *with* redirecting. I did change one thing - I set .onclick instead of .onauxclick. Does that make a difference? What does onauxclick do? – Cole Henrich Apr 13 '21 at 22:49
-
1