Use window.open() method to open URL in a new tab, but it could be open in the new browser window or a new tab depending on the browser setting and the parameter values.
window.open(URL, '_blank');
Example code open URL in a new tab in JavaScript
HTML example code:
Using _blank in the second parameter of window.open() to open a new tab in the example:-
<html>
<body>
<script>
function NewTab() {
window.open("https://www.eyehunts.com", "_blank");
}
// calling function
NewTab();
</script>
</body>
</html>
Output:
Do comment if you have any doubts and suggestions on these JS URL examples.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version