To simulate a user clicking forward or back button in the navigation bar in the browser, We can use the
forward()
or back()
methods available in the History
API.
Simulating a forward click
To simulate a forward click we can use the forward()
method like this,
// Simulate forward click
window.history.forward();
Simulating a back click
To simualte a back click we can use the back()
method like this,
// Simulate back click
window.history.back();