【问题标题】:history.back() doesn't work in firefox and internet explorer but it work in google chromehistory.back() 在 Firefox 和 Internet Explorer 中不起作用,但在 google chrome 中起作用
【发布时间】:2020-09-16 00:41:45
【问题描述】:

我在 JSP 上添加一个返回上一页的按钮时遇到了异常: 确实,当我单击按钮时,我填写的字段的值将丢失 在 firefoxinternet explorer 上检测到此行为, 另一方面,当我单击按钮时,chrome 上的一切正常,我填写的值会正确显示。 知道我尝试了下面的代码,你能在这一点上帮助我吗:

  • <button type="button" name="back" onCLick="history.back()">Retour</button>

  • <button type="button" name="back" onCLick="window.history.go(-1)">Retour</button>

  • <button type="button" name="back" onClick="goBack()">Retour</button>

    函数 goBack() { window.history.back(); }

-低于当前代码:

<button type="button" name="back" onclick="history.back()">Retour</button>

期待您的帮助。

【问题讨论】:

    标签: javascript jsp firefox onclick history


    【解决方案1】:

    您正在尝试使用 onclick 属性在按钮上设置事件处理程序。
    这不是 onClickonCLick。你很亲密:

    <button type="button" name="back" onclick="window.history.back()">Retour</button>
    

    【讨论】:

    • 总是存在相同的异常,我什至尝试过:&lt;input type="button" value="retour" onclick="window.history.back()"/&gt;
    • onclick="window.history.back()" 应该可以工作。你能用minimal reproducible example 来更新你的问题吗?理想情况下,使用 Stack Snippets([&lt;&gt;] 工具栏按钮;here's how to do one)可运行
    • 它只适用于谷歌浏览器,不适用于 Firefox 和 Internet Explorer
    【解决方案2】:

    问题已解决:

    服务器正在向页面发送“no-store”,因此 Firefox 在您离开页面后不会存储表单:

    HttpServletResponse httpResponse = (HttpServletResponse) response;
    httpResponse.setHeader("Cache-Control", "public"); // HTTP 1.1
    httpResponse.setHeader("Pragma", "public"); // HTTP 1.0
    httpResponse.setDateHeader("Expires", Long.MAX_VALUE); // Proxies.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-02
      • 2013-11-18
      • 1970-01-01
      • 2013-09-27
      相关资源
      最近更新 更多