• 🌙 Community Spirit

    Ramadan Mubarak! To honor this month, Crax has paused NSFW categories. Wishing you peace and growth!

Open a link in a new tab with JavaScript (1 Viewer)

Currently reading:
 Open a link in a new tab with JavaScript (1 Viewer)

Recently searched:

Engfree

Member
LV
0
Joined
Aug 20, 2023
Threads
10
Likes
0
Awards
2
Credits
819©
Cash
0$
avaScript is a programming language used to make websites more responsive, interactive, and user-friendly. It can access and modify an HTML web page's content, define the set of instructions that the web page should follow, and react to events triggered by the browser or user.

To open a URL in a new tab/window in JavaScript, we use the window.open(URL, target) method. To open a new tab, however, we must use _blank as the second parameter of this method.

Note: Avoid adding a third parameter because the link will be redirected to a new window rather than a new tab.

Code example​

Code:
<!DOCTYPE html>
<html>
  <head>
    <title>Educative</title>
  </head>
  <body>
    <button onclick="openTab()">Educative</button>
 
  <script>
    function openTab() {
    window.open("https://www.educative.io/", "_blank");
    }
  </script>

  </body>
</html>
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Recently searched:

Similar threads

Users who are viewing this thread

Top Bottom