从浏览器历史记录中删除当前页面 [英] Removing current page from browser history

查看:23
本文介绍了从浏览器历史记录中删除当前页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的网站中构建一个文本编辑器,工作流程如下.

I'm building a text editor in my website, the workflow is as follows.

  1. /list 中,用户从列表中选择他们想要编辑的条目,该列表会将他们带到 /edit/[article_id].
  2. 用户完成他们的工作,然后点击提交.
  3. 服务器处理该事物,并将它们重定向回 /edit/[article_id],它现在反映了编辑的工作.服务器还会在页面上激活一条闪现消息,表明编辑成功.
  1. In /list, the user picks an entry they want to edit from a list which takes them to /edit/[article_id].
  2. The user does their work, and then clicks submit.
  3. The server processes the thing, and redirects them back to /edit/[article_id] which by now reflects the edited work. The server also activates a flash message on the page to indicate the edit was successful.

此时,用户可能想要返回到 /list 并单击浏览器的后退按钮.这将根据他们提交的次数反复将他们带回编辑器.

By this point, the user probably wants to go back to /list and clicks the browser's Back button. This will take them back to the editor repeatedly depending on how many times they submitted.

我曾尝试在页面的某处放置一个后退按钮,但很多用户只是忽略了它.

I've tried putting a Back button somewhere on the page, but a good many users simply ignore it.

我宁愿不通过 AJAX 提交提交,因为这也会影响 Flash 消息系统.

I'd rather not make the submission posted via AJAX, since that would also affect the flash message system.

我喜欢做的是在用户提交时替换历史列表中的最后一个条目,而不改变其长度.可能吗?

What I like to do, is replace the last entry on the history list when the user submits, without changing its length. Is it possible?

推荐答案

试试这个

window.location.replace(url);

使用 replace() 后,当前页面将不会保存在会话历史记录中,这意味着用户将无法使用后退按钮导航到它.

after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.

这篇关于从浏览器历史记录中删除当前页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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