繁体   English   中英

可以在页面重新加载时触发JavaScript功能吗? [关闭]

[英]Possible to trigger JavaScript function on page reload? [closed]

当用户尝试重新加载当前页面时,是否可以触发JavaScript函数?

你的意思是确认一个“卸载”,即在用户离开当前页面之前执行一个功能。

<html>
<head>

<script type="text/javascript">
function mymessage()
{
    //this is the sample function code executed on "unload"
    alert("This message was triggered from the onunload event")
}
</script>
</head>

<body onunload="mymessage()">

<p>close this window</p>
</body>

</html>

要么

jQuery版本http://api.jquery.com/unload/

很难推断出你想要什么,但正如你在评论中所说的那样,你希望在刷新页面之前执行一个函数,你可以使用unload

$(window).unload(function() {
  alert('Handler for .unload() called.');
}); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM