还有另一个checkbox / backbutton问题 [英] Yet another checkbox/backbutton issue

查看:165
本文介绍了还有另一个checkbox / backbutton问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.jsp / JSTL / EL中实现了一个工作正常的网站。但是,根据浏览器(!),后退按钮的行为有所不同。

I've implemented a website in .jsp / JSTL / EL that works fine. However, depending on the browser (!), the behavior of the back button is varying a bit.

我确实没有双重发布不会警告用户他将再次发布),但显然这导致另一个问题:如果我使用Chrome的后退按钮,那么复选框的值不正确。

I did take care to not have double post (so that the browser does not warn the user that he's going to post again) but then apparently this leads to another issue: if I use the back button from Chrome, then the value of the checkboxes aren't correct.

这是我理解的情况:


  1. 用户在页面 / page1 检查复选框

  2. 发生POST,发生HTTP重定向

  3. 发生GET,第 / page2页

  4. 用户返回到 / page1 (这正是后退按钮的预期行为),该复选框仍处于选中状态。

  1. user is on page /page1 then checks a checkbox
  2. a POST is made, there's a HTTP redirect
  3. a GET is made, page /page2 displays fine, with the checkbox checked as it should be
  4. user hits the back button
  5. user goes back to /page1 as it was before the checkbox was checked (which is exactly the expected behavior for the back button) but the checkbox is still checked.



从查看服务器的日志和我的应用程序的日志,只要我看到,绝对没有传输到网络服务器。因此,它只是在客户端发生的事情。

From looking at the server's log and my application's log as far as I can see there's absolutely nothing transmitted to the webserver. So it's purely on the client side that things are happening.

发生了什么,如何解决这个问题? (不使用框架,这不是这个问题是什么)

What is going on and how can I fix this? (without using a framework, it's not what this question is about)

编辑我应该给一些更多的信息.​​.. webapp已经是一个有点花哨,每个页面服务 - 一个微小的URL类似的方式对应于一个状态。一切都是公开:任何人都可以看到任何人的页面(但它可以是私人的,与私人网址)。无论如何:如果用户在其网页上共享任何,当另一个用户打开一个网页时,该网页将正确显示,并且 正确初始化。

EDIT I should probably give a bit more info... The webapp is already a bit "fancy" in that each page served --in a tiny URL-like fashion-- corresponds to a state. Everything is "public": anyone can see anyone's pages (but it could be private, with private URLs). Anyway: if a user shares any of its page, when another user shall open a page it shall display correctly and the checkboxes are correctly initialized.

这说明问题不在服务器端,其中状态以某种方式不正确:如果用户A共享页... / 1d2eof然后用户B打开页面... / 1d2eof会看到正确的页面。

All this to say that the problem is not on the server side, where the "state" somehow wouldn't be correct: if user A share pages .../1d2eof then user B opening the page .../1d2eof shall see the correct page.

只有当用户使用后退按钮时才会出现这种情况。记住,在任何时候,我都可以在服务器端访问整个页面的状态。但我的问题是,显然当使用后退按钮没有联系我的服务器,所以我没有机会修复页面的用户使用后退按钮。

The only times where this gets messed up is when the user uses the back button. Remember that, at any point, I've got the full page's state accessible on the server side. However my issue is that apparently when using the back button nothing contacts my server, so I don't get the chance to "fix the page" for the user who used the back button.

也许双向重定向会有帮助!

Maybe a double redirect would help!?

推荐答案

按下返回按钮将恢复表单的最终状态。如果要将表单内容重置为HTML中指定的内容(即,在用户交互之前的状态),可以使用 document.formName.reset(),其中 formName 是表单的名称。 (不幸的是,有点难以检测到用户已经点击后退按钮并返回到当前页面,所以很难弄清楚何时运行上面的代码。)

This is a browser feature: pressing the "back" button will restore the final state of the form. If you want to reset the form contents to what was specified in the HTML (i.e., to a state before user interaction), you can use document.formName.reset(), where formName is the name of the form. (Unfortunately, it's a bit hard to detect that the user has hit the "back" button and returned to the current page, so it's tricky to figure out when to run the above bit of code.)

这篇关于还有另一个checkbox / backbutton问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆