How to Open URL in Same Window and Tab using JavaScript

In this tutorial, We have shared with you How to Open URLs in the Same Window and Tab using JavaScript.In HTML, the anchor tag is used to open URLs in the browser window. The href attribute is used to add a hyperlink to the tag and redirect one page to another. By default, the URL opens in the same window. You don’t need to set any attributes in the tag to open the URL in the same tab or window.
If you want to do this in HTML:
If you want to open the URL in JavaScript, use the window.open() method of Window. The window.open() JavaScript method lets you open the URL in the browser window or tab. You can use the _self value in the second parameter of the window.open() method to open the URL in the same tab and window with JavaScript.
Let’s try out the following example to understand how to method work with JavaScript: