How to open link in new tab on html?

2019-01-01 10:23发布

I'm working on an HTML project, and I can't find out how to open a link in a new tab without javascript.

I already know that <a href="http://www.WEBSITE_NAME.com"></a> opens the link in same tab. Any ideas how to make it open in a new one?

12条回答
步步皆殇っ
2楼-- · 2019-01-01 10:35

Default opens in same tab:

<a href="https://www.google.com/">Google.com </a>

Opens in new tab:

<a href="https://www.google.com/" target="_blank">Google.com </a>
查看更多
听够珍惜
3楼-- · 2019-01-01 10:38

If you would like to make the command once for your entire site, instead of having to do it after every link. Try this place within the Head of your web site and bingo.

<head>
<title>your text</title>
<base target="_blank">
</head>

hope this helps

查看更多
看淡一切
4楼-- · 2019-01-01 10:38

target="_blank" attribute will do the job. Just don't forget to add rel="noopener noreferrer" to solve the potential vulnerability. More on that here: https://dev.to/ben/the-targetblank-vulnerability-by-example

<a href="https://www.google.com/" target="_blank" rel="noopener noreferrer">Searcher</a>
查看更多
看风景的人
5楼-- · 2019-01-01 10:39

target='_blank' if you are not using XHTML.

查看更多
情到深处是孤独
6楼-- · 2019-01-01 10:48

You can use <a href='url' target="_blank">name</a>

Example <a href='https://www.facebook.com/hackbalteamz' target="_blank">Facebook</a>

查看更多
像晚风撩人
7楼-- · 2019-01-01 10:50

When to use target='_blank' :

The HTML version (Some devices not support it):

<a href="http://chriscoyier.net" target="_blank">This link will open in new window/tab</a>

The JavaScript version for all Devices :

The use of rel="external" is perfectly valid

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
    $('a[rel="external"]').attr('target', '_blank');
</script>

and for Jquery can try with the below one:

$("#content a[href^='http://']").attr("target","_blank");

If browser setting don't allow you to open in new windows :

href = "google.com";
onclick="window.open (this.href, ''); return false";
查看更多
登录 后发表回答