gpt4 book ai didi

javascript - 当用户单击关闭选项卡时如何打开新窗口浏览器?

转载 作者:行者123 更新时间:2023-11-28 19:27:08 25 4
gpt4 key购买 nike

当用户单击关闭选项卡时,我尝试使用此代码打开新窗口浏览器,但它不起作用

<script>

window.onbeforeunload = function(e) {
window.open("http://google.com");
window.stop();
};

</script>

那么,你能给我任何方法吗?

最佳答案

你不能。打开弹出窗口以响应窗口关闭是 forbidden by the specification :

An algorithm is allowed to show a popup if any of the following conditions is true:

The task in which the algorithm is running is currently processing an activation behavior whose click event was trusted.

The task in which the algorithm is running is currently running the event listener for a trusted event whose type is in the following list:

  • change
  • click
  • dblclick
  • mouseup
  • reset
  • submit

The task in which the algorithm is running was queued by an algorithm that was allowed to show a popup, and the chain of such algorithms started within a user-agent defined timeframe.

关于javascript - 当用户单击关闭选项卡时如何打开新窗口浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27645772/

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