To open the URL in New Tab using JavaScript, you can use the “window.open()” method. The window.open() method is used to open a new browser window or a new tab depending on the browser setting and the parameter values.
Syntax
window.open(URL, '_blank');
Step-by-step guide
- Use the window.open() method. This method is used to open a new window or a new tab.
- Pass the URL you want to open as the first parameter to window.open().
- To ensure the URL opens in a new tab, pass ‘_blank’ as the second parameter to window.open(). This tells the browser to open the URL in a new tab or window.
- The window.open() method returns a Window object representing the newly opened window or tab. You can use this Window object to control and interact with the new window or tab. If the new window or tab could not be opened, the window.open() will return null.
Example 1
<!DOCTYPE html>
<html>
<head>
<title>Open URL in New Tab</title>
</head>
<body>
<button onclick="openNewTab()">Open askjavascript.com in new tab</button>
<script>
function openNewTab() {
window.open('https://askjavascript.com', '_blank');
}
</script>
</body>
</html>
Output
If you click the link, you will see that the new tab will be opened with the URL: https://askjavascript.com
Example 2
<!DOCTYPE html>
<html>
<head>
<title>Open URL in New Tab</title>
</head>
<body>
<button onclick="openNewTab()">Open OpenAI in new tab</button>
<script>
function openNewTab() {
window.open('https://openai.com', '_blank');
}
</script>
</body>
</html>
Output
That’s it.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.