Categories
JavaScript Answers

How to check if the user can go back in browser history or not with JavaScript?

Spread the love

Sometimes, we want to check if the user can go back in browser history or not with JavaScript.

In this article, we’ll look at how to check if the user can go back in browser history or not with JavaScript.

How to check if the user can go back in browser history or not with JavaScript?

To check if the user can go back in browser history or not with JavaScript, we can call history.back or history.go.

For instance, we write

history.back();

or

history.go(-1);

to go back to the previous page.

Is there’s no previous page, they’ll do nothing.

Conclusion

To check if the user can go back in browser history or not with JavaScript, we can call history.back or history.go.

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 *