You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下Chrome与Edge的onbeforeunload事件异常问题咨询

关于Chrome/Edge中onbeforeunload触发时窗口偏移的问题

我通过onbeforeunload事件处理程序,实现了用户输入数据后关闭页面时触发浏览器“是否确定退出”弹窗的功能。此前该功能运行正常,但近期在Windows 10系统的最新版Chrome和Edge浏览器中出现异常:触发弹窗前,浏览器窗口会多次向左上方移动,直至到达屏幕左上角后才弹出确认框,而Firefox浏览器无此问题。

测试代码

<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
  <input id="1" type="radio" onchange="change()">
  <label for="1">Test</label>
<script>
  var changed = false;
  
  function change() {
    changed = true;
  }
  
  window.onbeforeunload = function (e) {
    if (changed) {
      e.preventDefault();
      e.returnValue = true;
    }
  };
</script>
</body>

</html>

异常状态截图

异常时浏览器状态

请问这是浏览器bug,还是Chrome和Edge对该事件的处理方式有更新?


内容的提问来源于stack exchange,提问作者TomazicM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 20:34:54