How to open New tab using javascript or jquery and open href in it?

I would like to capture href of anchor tag<a> on click, and open that link in new tab using javascript or jquery, how to do this?

Asked by:- Sam
: 5970 At:- 10/24/2017 7:21:40 AM
javascript jquery open link in new tab

3 Answers
profileImage Answered by:- pika

Try opening pages using with a different window name will open in a new browser window like a popup, OR open in a new tab, if the user has allowed the browser to do so.

Your code should be

var win ='', '_blank');
if (win) {
    //Browser allows the new tab to open
} else {
    //Browser has blocked it
    alert('Please allow popups for this website');

Or try this code to

<a href="url" target="_newtab">Anchor Text</a>

In javascript you can use'page.html','_newtab');

For HTML check Open link in new tab using HTML

At:- 10/25/2017 8:27:50 AM

profileImage Answered by:- vikas_jk"url","_blank") , may be blocked by chrome or any other browsers by pop-up so you may like to try this JS code

document.querySelector('#myButton').onclick = function() {
    var redirectWindow ='', '_blank');


You can also give a try to below Javascript code

<a class="link">Link</a>
<script  type="text/javascript">
At:- 6/23/2020 2:36:42 PM

profileImage Answered by:- bhanu

Using jQuery, you can open new tab in browser with code below

$('#btnId').click(function () {
    var redirectWindow ='', '_blank');

Using Pure Javascript

function openInNewTab(url) {, '_blank').focus();

and you can use it as below in HTML

<div onclick="openInNewTab('');">Open in New Tab</div>

That's it.

At:- 11/12/2021 1:12:45 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use