Anchor links pointing to a fragment fires History API’s “popstate” event

I hit an interesting “bug” while working on a SPA application. Clicking an anchor link that points to a fragment on the page fires the History API’s popstate event. This triggers some logic on my end, which was not my intent. I fixed that with a bit of JavaScript, and I had to share the snippet.


This content originally appeared on Krasimir Tsonev - blog and was authored by Krasimir Tsonev - blog

I hit an interesting "bug" while working on a SPA application. Clicking an anchor link that points to a fragment on the page fires the History API's popstate event. This triggers some logic on my end, which was not my intent. I fixed that with a bit of JavaScript, and I had to share the snippet.


This content originally appeared on Krasimir Tsonev - blog and was authored by Krasimir Tsonev - blog


Print Share Comment Cite Upload Translate Updates
APA

Krasimir Tsonev - blog | Sciencx (2022-11-15T20:42:44+00:00) Anchor links pointing to a fragment fires History API’s “popstate” event. Retrieved from https://www.scien.cx/2022/11/15/anchor-links-pointing-to-a-fragment-fires-history-apis-popstate-event/

MLA
" » Anchor links pointing to a fragment fires History API’s “popstate” event." Krasimir Tsonev - blog | Sciencx - Tuesday November 15, 2022, https://www.scien.cx/2022/11/15/anchor-links-pointing-to-a-fragment-fires-history-apis-popstate-event/
HARVARD
Krasimir Tsonev - blog | Sciencx Tuesday November 15, 2022 » Anchor links pointing to a fragment fires History API’s “popstate” event., viewed ,<https://www.scien.cx/2022/11/15/anchor-links-pointing-to-a-fragment-fires-history-apis-popstate-event/>
VANCOUVER
Krasimir Tsonev - blog | Sciencx - » Anchor links pointing to a fragment fires History API’s “popstate” event. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/15/anchor-links-pointing-to-a-fragment-fires-history-apis-popstate-event/
CHICAGO
" » Anchor links pointing to a fragment fires History API’s “popstate” event." Krasimir Tsonev - blog | Sciencx - Accessed . https://www.scien.cx/2022/11/15/anchor-links-pointing-to-a-fragment-fires-history-apis-popstate-event/
IEEE
" » Anchor links pointing to a fragment fires History API’s “popstate” event." Krasimir Tsonev - blog | Sciencx [Online]. Available: https://www.scien.cx/2022/11/15/anchor-links-pointing-to-a-fragment-fires-history-apis-popstate-event/. [Accessed: ]
rf:citation
» Anchor links pointing to a fragment fires History API’s “popstate” event | Krasimir Tsonev - blog | Sciencx | https://www.scien.cx/2022/11/15/anchor-links-pointing-to-a-fragment-fires-history-apis-popstate-event/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.