Open a link in a new tab with JavaScript | Web Scripts | Crax

Welcome To Crax.Pro Forum!

Check our new Marketplace at Crax.Shop

   Login! SignUp Now!
  • We are in solidarity with our brothers and sisters in Palestine. Free Palestine. To learn more visit this Page

  • Crax.Pro domain has been taken down!

    Alternatives: Craxpro.io | Craxpro.com

Open a link in a new tab with JavaScript

Open a link in a new tab with JavaScript

LV
0
 

Engfree

Member
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.

Top Bottom