本文翻譯自:How to open link in new tab on html?
I'm working on an HTML project, and I can't find out how to open a link in a new tab without javascript. 我正在處理一個HTML項目,但是我不知道如何在沒有JavaScript的情況下在新標籤頁中打開鏈接。
I already know that <a href="http://www.WEBSITE_NAME.com"></a>
opens the link in same tab. 我已經知道<a href="http://www.WEBSITE_NAME.com"></a>
在同一標籤中打開了鏈接。 Any ideas how to make it open in a new one? 有什麼想法如何使其在新的環境中打開嗎?
#1樓
參考:https://stackoom.com/question/1CJTe/如何在HTML的新標籤頁中打開鏈接
#2樓
Set the 'target' attribute of the link to _blank
: 將鏈接的'target'屬性設置爲_blank
:
<a href="#" target="_blank" rel="noopener noreferrer">Link</a>
Edit: for other examples, see here: http://www.w3schools.com/tags/att_a_target.asp 編輯:有關其他示例,請參見此處: http : //www.w3schools.com/tags/att_a_target.asp
(Note: I previously suggested blank
instead of _blank
because, if used, it'll open a new tab and then use the same tab if the link is clicked again. However, this is only because, as GolezTrol pointed out, it refers to the name a of a frame/window, which would be set and used when the link is pressed again to open it in the same tab). (注意:我以前建議使用blank
而不是_blank
因爲如果使用它,它將打開一個新選項卡,如果再次單擊該鏈接,則將使用相同的選項卡。但是,這僅是因爲正如GolezTrol所指出的那樣,框架/窗口的名稱a,當再次按下鏈接以在同一選項卡中將其打開時,將設置並使用該名稱。
Security Consideration! 安全考慮!
The rel="noopener noreferrer"
is to prevent the newly opened tab from being able to modify the original tab maliciously. rel="noopener noreferrer"
可以防止新打開的選項卡能夠惡意修改原始選項卡。 For more information about this vulnerability see these resources: 有關此漏洞的更多信息,請參見以下資源:
- https://dev.to/ben/the-targetblank-vulnerability-by-example https://dev.to/ben/the-targetblank-vulnerability-by-example
- https://support.detectify.com/customer/portal/articles/2792257-external-links-using-target-_blank- https://support.detectify.com/customer/portal/articles/2792257-external-links-using-target-_blank-
#3樓
target='_blank'
如果您未使用XHTML)。
#4樓
使用target="_blank"
:
<a href="http://www.example.com/" target="_blank" rel="noopener noreferrer">This will open in a new window!</a>
#5樓
Use the "target" attribute of the a tag and assign it to _blank. 使用標籤的“目標”屬性,並將其分配給_blank。 That is: 那是:
<a href="http://www.google.com" target="_blank" >Google in a New Tab or Window depending on the browser's capabilities</a>
#6樓
target =“ _ blank”總是爲每次點擊打開一個新標籤,而target =“ tabName”會爲每個點擊打開一個新標籤。