Open a link in a new tab with JavaScript

dblackcat

dblackcat

Golden Member
Joined
August 1, 2024
Messages
291
Reaction score
2,618
Points
93
  • Thread Author
  • #1
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.. 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>
 

Similar threads

Vce.G0d
Replies
0
Views
718
Vce.G0d
Vce.G0d
Vce.G0d
Replies
1
Views
729
iwakura
I
BinaryBrute
Replies
3
Views
1K
hakcerfdfd
H
ApexWolf
Replies
0
Views
577
ApexWolf
ApexWolf
ApexWolf
Replies
0
Views
486
ApexWolf
ApexWolf
  • Tags
    a in javascript link new open user experience web development with