Track when user hits back button on the browser

前端 未结 7 1226
陌清茗
陌清茗 2020-11-28 10:56

Is it possible to detect when the user clicks on the browser\'s back button?

I have an Ajax application and if I can detect when the user clicks on the back button I

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 11:19

    There are multiple ways of doing it, though some will only work in certain browsers. One that I know off the top of my head is to embed a tiny near-invisible iframe on the page. When the user hits the back button the iframe is navigated back which you can detect and then update your page. Here is another solution.

    You might also want to go view source on something like gmail and see how they do it.

    Here's a library for the sort of thing you're looking for by the way

提交回复
热议问题