Open URL in Same Tab using JavaScript

To open URL in same window or in same tab using javascript, we can use two methods.

First one is window.open() method and another one is window.location.href.

Let’s check the first option window.open().

If we use below syntax, It will open link in new tab or window.

window.open(“www.codefixup.com”);  // open link in another tab

To open URL in same Window or Tab use ‘_self’ value in second paramater of window.open() method. Like below:

window.open(“www.codefixup.com”, “_self”);  // open in same tab or window

The second option to open link in same tab or window, use below syntax:

window.location.href = “https://www.codefixup.com”;

Recommended Posts For You

About Harish

I am professional web developer and blogger. Use this blog to share own api and other web development experience with you. I do accept paid work. Write to me at - [email protected]

View all posts by Harish