gpt4 book ai didi

javascript - 将弃用的 Chrome V80 功能

转载 作者:行者123 更新时间:2023-12-03 16:30:26 25 4
gpt4 key购买 nike

从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com