javascriptpopup-blocker

How to open an URL in a new tab not in a new window


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.


Solution

  • 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