<!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>
<title></title>
</head>
<body>
<div>
<input type="button" οnclick="btnClick()" value="点击" />
</div>
<script src="script/jquery-1.7.js" type="text/javascript"></script>
<script type="text/javascript">
function btnClick() {
$.ajax({
url: "handler/test.ashx?ra=" + Math.random(),
data: { user: "aaa", pwd: "pwd" },
type: "post",
dataType: "html",
cache: false,
success: function (data) {
//alert(data);
}
});
}
/*#######兼容脚本,需要先引入jquery######*/
var UnloadConfirm = {};
UnloadConfirm.set = function () {
var _browser = $.browser.msie;
if (_browser) {
$(window).unload(function () { btnClick(); });
}
else {
window.onbeforeunload = function (b) {
btnClick();
b = b || window.event;
b.returnValue = "";
//return ""
}
}
};
// UnloadConfirm.clear = function () {
// window.onbeforeunload = function () { }
// };
UnloadConfirm.set();
</script>
</body>
</html>
借鉴了一下网上的方法,整合了一下,测试通过