Hello, I was working on HTML and would like to know how can I open anchor link ( HTML ) in a new tab instead of loading URL on the same page? Suppose this is my anchor tag HTML
<a href="URL">Open in new tabs</a>
Thanks.
You can simply use target="_blank" to open new tab and your link it, here is the sample HTML
<a href="URL" target="_blank">Open in new tabs</a>
In the above HTML target attribute specifies where to open the linked document, other values of target attribute is as below
Value | Description |
---|---|
_blank | Opens the linked document in a new window or tab |
_self | Opens the linked document in the same frame as it was clicked (this is default) |
_parent | Opens the linked document in the parent frame |
_top | Opens the linked document in the full body of the window |
framename | Opens the linked document in a named frame |
If you want to open a button in new window you can use code below
<button class="btn btn-primary" onClick="window.open('http://www.example.com');">
Open
</button>
Above answer is correct, but here are multiple version of opening a link in new tab
Using HTML
<a href="example.com" target="_blank">This link will open in new window/tab</a>
Using jQuery
By Selecting all anchor tags which has rel="external", set attribute
<script type="text/javascript">
$('a[rel="external"]').attr('target', '_blank');
</script>
If you want to create anchor dynamically and open in new tab using Javascript, check https://qawithexperts.com/questions/142/how-to-open-new-tab-using-javascript-or-jquery-and-open-href
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly