关闭网页前自动调用函数 [英] Automatically call a function before closing the webpage

查看:264
本文介绍了关闭网页前自动调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在关闭网页之前,我需要一个代码来调用函数或事件(即,在关闭页面之前,我需要调用session_onend事件).我没有使用登录和注销页面.我仍然需要计算访客时间的持续时间.我热切地等待您的回复.


在此先感谢..

问候


Sasikumar
MCAMDOIS

解决方案


您可以使用JavaScript浏览器关闭事件.但是,如果您的用户在浏览器的地址栏中键入不同的URL并重定向到另一个网站,则此方法将无效.

 <   html  > ; 
<  头部 > 
<  脚本 > 
函数ThankForVisiting()
{
  alert(谢谢您访问我们!");
}
<  /script  > 
<  /head  > 
<  正文    ="   ThanksForVisiting();" <  /body  > 
<  /html  >  



希望这会有所帮助.


hi
I need a code to call a function or an event before closing the web page (i.e. I need to call session_onend event before closing the page). I don''t have use the login and logout page. Still I need to calculate the duration of the visitors hours. I eagerly waiting for your replies..


thanks in advance..

regards


Sasikumar
MCAMDOIS

解决方案

Hi,
You can use JavaScript browser close event. But if your user type different URL at browser''s address bar and redirects to another web site this approach wont work.

<html>
<head>
<script>
function ThanksForVisiting()
{
  alert("Thank you for visiting us!!");
}
</script>
</head>
<body onunload="ThanksForVisiting();">
</body>
</html>



Hope this will help.


这篇关于关闭网页前自动调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆