11

How to Open URL in Same Window and Tab using JavaScript

 2 years ago
source link: https://www.codexworld.com/how-to/open-url-in-same-browser-window-tab-using-javascript/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Home  »  How To Guides  »  JavaScript   »   How to Open URL in Same Window and Tab using JavaScript

How to Open URL in Same Window and Tab using JavaScript


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 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 using JavaScript.

window.open("https://www.codexworld.com/", "_self");

Leave a reply

Cancel

Comment*

Your Name*

Your Email*

Your Website


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK