- <script type="text/javascript">
- <!--
- function callAjax(webUrl, queryString) {
- var xmlHttpObject = null;
- try {
- // Firefox, Opera 8.0+, Safari...
- xmlHttpObject = new XMLHttpRequest();
- }
- catch (ex) {
- // Internet Explorer...
- try {
- xmlHttpObject = new ActiveXObject('Msxml2.XMLHTTP');
- }
- catch (ex) {
- xmlHttpObject = new ActiveXObject('Microsoft.XMLHTTP');
- }
- }
- if (xmlHttpObject == null) {
- window.alert('AJAX is not available in this browser');
- return;
- }
- xmlHttpObject.open("GET", webUrl + queryString, false);
- xmlHttpObject.send();
- return xmlText;
- }
- // -->
- </script>
- <script type="text/javascript">
- <!--
- var g_isPostBack = false;
- window.onbeforeunload = function () {
- if (g_isPostBack == true)
- return;
- var closeMessage =
- 'You are exiting this page.\\n' +
- 'If you have made changes without saving, your changes will be lost.\\n' +
- 'Are you sure that you want to exit?';
- if (window.event) {
- // IE
- window.event.returnValue = closeMessage;
- }
- else {
- // 其它浏览器
- return closeMessage;
- }
- g_isPostBack = false;
- }
- window.onunload = function () {
- if (g_isPostBack == true)
- return;
- var webUrl = 'LogoffPage.aspx';
- var queryString = '?LogoffDatabase=Y&UserID=' + '<%= Session["UserID"] %>';
- var returnCode = callAjax(webUrl, queryString);
- alert(returnCode);
- }
- // -->
- </script>
- //该片段来自于http://www.codesnippet.cn/detail/201120137350.html
来源: http://www.codesnippet.cn/detail/201120137350.html