Browser back button restores empty fields

后端 未结 6 1418
小鲜肉
小鲜肉 2020-12-05 09:02

I have a web page x.php (in a password protected area of my web site) which has a form and a button which uses the POST method to send the form dat

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 09:40

    I poked around and this is quite a hard problem. Its also a major pain in the ass for Dynamically modified content. You visit the page, javascript augments it with your instruction, you go to the next page, and come back, and javascript has forgotten. And there's no way to simply update the page server-side, because the page comes out of cache.

    So I devised a back-button-cache-breaker.

    Its evil and bad-for-the-web, but it makes it able for pages to behave how people expect them to behave instead of magically warping all over the place.

    
    

    This will do a bit of magic in that it detects whether or not the page you are /currently/ viewing was loaded from cache or not.

    if you're there the first time, it will detect "no hash" , and add "#_" to the page url. if you're there for the >1st time ( ie: not a direct link to the page ), the page already has the #_ on it, so it removes it and in the process of removing it, triggers a page reload.

提交回复
热议问题