In HTML, <a> tag is used to open URL on browser’s window. The href
attribute allows to add a hyperlink to the <a> tag and redirect one page to another. By default, the URL is opened in the same window. So, you don’t need to define any attribute in <a> tag to open URL in the same tab or window.
<a href="https://www.codexworld.com">Visit CodexWorld</a>
If you want to open URL in JavaScript, the open() method of the Window interface is the easiest way. The JavaScript window.open() method allows you to open URL in the browser tab or window. You can use _self
value in the second parameter of the window.open() method to open the URL in the same tab and in the same window with JavaScript.
The following code snippet opens the URL in the same window and tab of the browser using JavaScript.
window.open("https://www.codexworld.com/", "_self");
Wow very very useful code for same window. Brilliant work Sir. I am very very happy to use this code and working super. Thank you sir