How to Open a Link in a New Tab with JavaScript

By Birtchum Thompson | March 24, 2020

Opening a link in a new tab with JavaScript is as simple as it is with the HTML <a> tag’s target attribute. In fact, it even uses "_blank" as the target for the new tab just like the HTML <a> tag.

The JavaScript window object is a representation of the browser window and provides some helpful functionality for the web. For opening a new tab, window’s open() function is used. The open() function must receive 2 arguments for our purpose: the URL to open and "_blank" as the second argument. The code should look similar the the example below.

 JavaScript
Share this Content

Join the Discussion

Also Read

JavaScript logo and function text on grey background
Write Self-Executing JavaScript Functions

Make variable maintenance easier with self-executing functions.

AWS CloudFront logo on grey background
Invalidate CloudFront Objects with Boto3

Learn to Invalidate CloudFront objects by paths with Boto3.

UFW, Ubuntu, and firewall logos on dark grey background
Allow SMB in UFW

Allow SMB traffic in UFW on Ubuntu & Debian.

Python logo and red trash can
Delete Files Older than X Days in Python

Create a Python script to delete files older than x days.