javascript - 将弃用的 Chrome V80 功能

标签 javascript google-chrome

从 Chrome V80 开始,很少有像 beforeunload、unload 等事件被弃用。我们如何在 JavaScript 中进一步处理此类现有事件?

我的要求是当用户尝试刷新/重新加载页面(F5 或 ctrl+r)或浏览器后退按钮时提醒,我需要提醒并在确认后,我需要重新加载或后退。这是在 JSF2.2 中

但该行为不应影响其他浏览器中的功能。

谁能帮我解决这个问题

最佳答案

beforeunload 事件仍然可用。正在改变的是在页面关闭期间执行同步 XHR 的能力。从长远来看,真正有害的是同步 XHR,因为它会损害用户体验。您仍然可以使用 beforeunloadGetting Rid of Synchronous XHRs特别提到这一点:

Note: We expect to remove support for synchronous use of XMLHTTPRequest() during page unloads in Chrome in version 80, scheduled to ship early in 2020.

Chrome Platform Status: Disallow sync XHR in page dismissal 中也有关于此特定更改的信息.在 Deprecations and removals in Chrome 80 中有关于 Chrome 80 的更多信息:

Chrome now disallows synchronous calls to XMLHTTPRequest() during page dismissal when the page is being navigated away from or is closed by the user. This applies to beforeunload, unload, pagehide, and visibilitychange.

To ensure that data is sent to the server when a page unloads, we recommend sendBeacon() or Fetch keep-alive. For now, enterprise users can use the AllowSyncXHRInPageDismissal policy flag and developers can use the origin trial flag allow-sync-xhr-in-page-dismissal to allow synchronous XHR requests during page unload. This is a temporary "opt-out" measure, and we expect to remove this flag in Chrome 82.

请注意,页面关闭期间的弹出窗口也将被禁止:

Pages may no longer use window.open() to open a new page during unload. The Chrome popup blocker already prohibited this, but now it is prohibited whether or not the popup blocker is enabled.

关于javascript - 将弃用的 Chrome V80 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59858513/

相关文章:

javascript - 可暂停的 Javascript 函数

html - 渐变在 Firefox 和 IE 中不起作用

javascript - 将 jquery 数组中的值设置为 span

javascript - 我可以使用 AngularJS 中动态分配的 min 属性来验证输入吗?

google-chrome - 在谷歌浏览器扩展程序中存储首选项

javascript - Android Chrome 网站

JavaScript 为 event.key 警报 event.keyCode 制作基本的polyfill,以实现 Chrome 的现代化

java - 用Appium测试后关闭Chrome浏览器? java

javascript - 为什么这段代码这么慢?

javascript - 输入并加载 url 来调用 JS 时要使用哪个 XUL 元素?