在浏览器中单击返回或使用history.go(-1)后删除特定字段
我有一个带有 capacha 的表单,如果 capacha 输入错误,提交后页面会执行“history.go(-1)”,并且所有包含 capacha 输入的字段都会返回到屏幕上,
现在我有一个 js清除这一点 - 但现在我在几个地方需要它,我想知道是否可以在返回后清除表单字段,并使用与 html 表单相关的内容或什么
感谢
i have a form with a capacha, if the capacha was entered wrong, after submit the page is doing a "history.go(-1)" and all fields include the capacha input are back on the screen
right now i have a js that clear that - but now that i need it in several places, i want to know if it possible to clear a form field after back with something related to the html form or what ever
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过查看缓存控制验证码图像(或页面加载它)?
Have you tried looking into cache controlling the CAPTCHA image (or the page that loads it up)?
我认为使用“history.go(-1)”和 JavaScript 根本不是一个好主意。
您必须在服务器端验证验证码,并在服务器端选择您必须呈现的页面?再次使用验证码或下一步。
I think it's a bad idea to use "history.go(-1)" and JavaScript at all.
You must validate captcha on the server side and in server side choice that page you must render? again with captcha or next.
我认为仅使用 html 是不可能的,需要添加一些编程。
您可以在文档的
onload
事件上调用 js 函数。函数可以是这样的:
你也可以在这个函数中使用一些ajax来每次都获取一个新的验证码。
您可以将此函数放在母版/标题页中,这样您就不需要将其复制到所有页面(因为您可能需要使选择器更精确)。
I dont think its possible with only html, need to add some programming.
You can have js function that is called on
onload
event of document.function can be like this:
And you can also use some ajax in this function to get a new captcha every time.
you can place this function in your master/header page, so that you don't need to copy it to all pages (for that you may need to make selector more precise).
另一种选择是您可以在每次访问页面时重命名表单字段。将时间戳附加到名称。这样浏览器就不会自动填充它。您可能需要稍微调整后端代码来解决这个问题。
Another option is that you can rename the form field with every visit to the page. Append a timestamp to the name. That way the browser won't autofill it. You probably will have to adjust your backend code slightly to account for this.