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
.