gpt4 book ai didi

javascript - 当有人重新加载页面或单击链接时,我如何捕获 JavaScript 事件?

转载 作者:行者123 更新时间:2023-11-30 13:32:21 26 4
gpt4 key购买 nike

例如,如果互联网连接速度较慢,页面可能需要几秒钟才能加载。

当用户按下重新加载或点击页面上的任何链接时,我想显示一条消息,例如:“页面正在加载...”

我无法为页面中的所有链接添加 onclick 事件,也无法通过浏览器的重新加载按钮添加;甚至有这样的事件吗?

感谢您的回复!

最佳答案

添加 document.onbeforeunload <head> 顶部的处理程序部分以便尽快执行:

<head>
<script>
window.onbeforeunload = function(e) {
return "The page is loading... Are You Sure?"
};

window.onload = function(e) {
document.getElementsByTagName('title')[0].innerHTML = 'Loaded';
window.onbeforeunload = function() { };
}
</script>

<title>Loading</title>
...
</head>
...

关于javascript - 当有人重新加载页面或单击链接时,我如何捕获 JavaScript 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6287884/

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