可以使用window.open('url','_blank')
的onclickevent一个新的选项卡后,打开:
<a href="https://google.com" onclick="window.open('https://youtube.com','_blank'); return false;">click here for a new tab</a>
,或者您可以使用window.open('url','','width=,height=')
打开一个新窗口:
<a href="https://google.com" onclick="window.open('https://youtube.com','','width=800,height=700'); return false;">click here for a new window...</a>
在这个例子中它会打开youtube(REAL_URL
)而不是goo GLE(FAKE_URL
)
> JSFiddle - Example
说明:
你的错误是的target="_blank"
附加改变你<a href="..."></a>
的行为,但不是你的document.location.href='...'
。因此,如果没有document.location.href='...'
,它会在新选项卡中打开FAKE_URL
。
为什么你想要在那里的onclick事件? –
[JavaScript在新窗口中打开,而不是标签]可能重复(http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab) –
'' – Hearner