0

there are many answers on how to open a URL in a new window using window.open() but this opens a popup window and that's not what I need.
The problem is: Many users have their browsers set to block popup windows. On the other hand, many websites can open new tabs inside thw current window avoiding the popup blocker to kick in.

window.open('page.htm','_blank')  

triggers the popup blocker,

window.location.href='page.htm','_blank'  

opens the URL in the same tab, just if '_blank' was omitted.

So here's the question:
Is there a way to tell Javascript to behave just as if the target='_blank' attribute was included in an ordinary link?
in other words:
How is it possible to open a new tab, preferably using document.location.href?
I emphasize that I don't want to open a new window because that activates the popup blocker.
I need a new tab inside the current window.
Again, any answers proposing window.open() are useless for me, so please don't recommend anything that opens a new window.

  • This question has been asked **many** times before. Please try searching first. [Open a URL in a new tab using JavaScript](http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript) – Christian Apr 01 '15 at 06:38

1 Answers1

2

This may help.

<div onclick="OpenNewTab('http://www.stackoverflow.com');">Click here to Open New Tab</div>

function OpenNewTab(url) {
  var newwindow = window.open(url, '_blank');
  newwindow .focus();
}

Working Fiddle

Birlla
  • 1,700
  • 2
  • 15
  • 17
  • I tried this in the fiddle and it works well with stackoverflow.com. I included it into my HTML file to open a local page and it triggers the popup blocker. – Gerald Gerosch Apr 01 '15 at 07:06
  • Maybe I did something wrong trying out, but now it works. Thank you very much for this quick and easy solution. – Gerald Gerosch Apr 01 '15 at 07:23