you can use window.open('url','_blank')
to open after the onclickevent a new tab:
<a href="https://google.com" onclick="window.open('https://youtube.com','_blank'); return false;">click here for a new tab</a>
or you can use window.open('url','','width=,height=')
to open a new window:
<a href="https://google.com" onclick="window.open('https://youtube.com','','width=800,height=700'); return false;">click here for a new window...</a>
In this example it will open youtube (REAL_URL
) instead of google (FAKE_URL
)
> JSFiddle - Example
Explanation:
Your mistake was that the add of target="_blank"
changes the behaviour of your <a href="..."></a>
, but not your document.location.href='...'
. So without the document.location.href='...'
it would open the FAKE_URL
in a new tab.