复选框/后退按钮问题取决于浏览器 [英] checkbox/backbutton issue depending on the browser

查看:86
本文介绍了复选框/后退按钮问题取决于浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在.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. 用户点击后退按钮
  5. 用户返回到/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.

从查看服务器的日志和我的应用程序的日志来看,我发现绝对没有任何内容传输到Web服务器.因此,事情完全在客户端进行.

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的形式出现)都对应一个状态.一切都是公开的":任何人都可以看到任何人的页面(但可以是私有的,带有私有URL).无论如何:如果用户共享其页面的 any ,则当另一个用户打开页面时,它将正确显示,并且复选框已正确初始化.

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.)

这篇关于复选框/后退按钮问题取决于浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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