admin管理员组文章数量:1354447
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
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
Share Improve this question asked Oct 11, 2013 at 14:28 Marc-André TherrienMarc-André Therrien 5495 silver badges25 bronze badges 3- soooo, why exactly is it you're changing the hashtag of the URL if you don't need the hashtag history? – Zathrus Writer Commented Oct 11, 2013 at 14:33
- 4 well the most simple thing would be to stop changing the url, and find another way to slide the images – Bobby5193 Commented Oct 11, 2013 at 14:33
- I agree with that, i will probably change it to a jquery slider instead of css3 – Marc-André Therrien Commented Oct 11, 2013 at 15:35
2 Answers
Reset to default 4window.location.replace("#image" + image);
This does a simple redirect without adding it to the history.
MDN: https://developer.mozilla/en-US/docs/Web/API/Location.replace
Previous question: What's the difference between window.location= and window.location.replace()?
Use History API:
history.replaceState({}, document.title, "#image" + image);
history.replaceState() operates exactly like history.pushState() except that replaceState() modifies the current history entry instead of creating a new one.
replaceState() is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.
本文标签: javascriptHow to not keep history of html anchorStack Overflow
版权声明:本文标题:javascript - How to not keep history of html anchor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743992073a2572328.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论