How to simulate a user clicking forward and back buttons in the browser using JavaScript?

September 9, 2020 - 1 min read

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();

Feel free to share if you found this useful 😃.