javaScript如何监听浏览器关闭事件
最近写东西的时候发现需要对浏览器的关闭进行监听,当用户关闭的时候需要调用session.invalid();清空session信息,但是仔细一查手册发现无论是body还是window都没有onclose事件,之后onload,onunload,beforeunload三个事件
然而三个时间无论是哪个都无法单独解决单独监听浏览器关闭的事件,因为在浏览器正常运行时先加载的是beforeunload->onunload->onload 但是麻烦的是如果刷新页面时是执行beforeunload->onunload,如果关闭浏览器的话是执行onunload.如果单单监听onunload的话是无法区别用户是刷新还是关闭窗口的.所以就要用beforeunload来监测了
window.onbeforeunload=onclose;
function onclose()
{
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
removeSession();//这里添加具体的处理方案
}
}
经过测试,IE7浏览器可以监测监听到 alt+f4 或者单击右上角小叉子退出,但是对于多选项卡浏览的用户貌似无法监听到这点比较可惜~
上天保佑我离数+电工过关吧 阿门!
相关文档:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript</t ......
Although the days of long and tedious code branches to target specific browsers in JavaScript are over, once in a while it's still necessary to do some simple code branching and object detection to ensure that a certain piece of code is working properly on a user's machine.
In this article, I ......
<HTML>
<HEAD>
<title>WEB页面导出为EXCEL文档的方法
</title>
</HEAD>
<body>
<BR>
<table id = "PrintA" width="100%" border="1" cellspacing="0" cellpadding="0" bgcolor = "#61FF13">
<TR style="text-align : center;" mce_style="text-ali ......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>select-option onclick </title>
<script type="text/javascript" >
function simOptionClick4IE(){  ......
最近做的项目中有个要求,需要将数据导出到Excel中,关于这个就不是什么问题,网上的资料很多。可当Table中有Input(text)之类的元素是怎么办?
做法:
修改Input的outerHTML;
具体例子:
function resetInput()
{
&nbs ......