可以使用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