简体   繁体   English

在后浏览器按钮上刷新页面

[英]Refresh page on back browser button

is possible reload taget page with back button of browser? 浏览器的后退按钮可以重新加载标记页面吗?

Example: I want reset all data/cache of page when user press back button on browser. 示例:当用户在浏览器上按返回按钮时,我想重置页面的所有数据/缓存。

Although your questions is very poorly written, I believe it is more important that you get the answer you're looking for. 尽管您的问题写得很差,但我认为获得所需的答案更为重要。

Do the following: 请执行下列操作:

  1. Add event listener to the window/document(in your case, keydown) 将事件侦听器添加到窗口/文档(在您的情况下为keydown)
  2. Get the ascii code of backspace(0x08 or 8 in decimal) 获取退格的ASCII码(0x08或十进制的8)
  3. Prevent the default functionality of keydown 阻止默认的按键功能
  4. Refresh the page if it is backspace 如果页面是退格键,请刷新

Here it is in code. 它在代码中。

window.addEventListener('keydown', function(e)
{
    if( e.keyCode == '8' )
    {
        e.preventDefault();  // prevent backspace from going to browser
                          // history
        // add reload code
        location.reload();
    }
}, false);

Link to event listener 链接到事件监听器

MDN Event Listeners MDN事件监听器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM