Categories
JavaScript Answers

How to open URL in same window and in same tab with JavaScript?

Spread the love

Sometimes, we want to open URL in same window and in same tab with JavaScript.

In this article, we’ll look at how to open URL in same window and in same tab with JavaScript.

How to open URL in same window and in same tab with JavaScript?

To open URL in same window and in same tab with JavaScript, we call window.open with '_self'.

For instance, we write

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

to call window.open to open https://www.example.com in the same window or tab with '_self'.

Conclusion

To open URL in same window and in same tab with JavaScript, we call window.open with '_self'.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *