Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not keep history of html anchor

I'm creating an image slider in css3 with the :target selector. I have a next and previous button that are executing this line of javascript

window.location = "#image" + image;

The problem is that if i click the back button of my browser, it shows the previous image of the slider. I want the back button to go to the previous page, not the previous anchor.

Thanks for the help

like image 965
Marc-André Therrien Avatar asked Feb 15 '23 00:02

Marc-André Therrien


1 Answers

window.location.replace("#image" + image);

This does a simple redirect without adding it to the history.
MDN: https://developer.mozilla.org/en-US/docs/Web/API/Location.replace
Previous question: What's the difference between window.location= and window.location.replace()?

like image 86
17xande Avatar answered Feb 28 '23 01:02

17xande