开发者

To have an ajax call using javascript before window is closed in IE

开发者 https://www.devze.com 2023-04-05 01:45 出处:网络
I need to make an AJAX call using javascript before window is closed in IE function fun(){ if((window.event.clientX<0) || (window.event.clientY<0)) {

I need to make an AJAX call using javascript before window is closed in IE

function fun(){
    if((window.event.clientX<0) || (window.event.clientY<0)) {
      //Make the ajax call
    }
}

I have called the function onload of my webpage, it is working fine for browser having single tab but failing for browser having multiple tabs.

I have also tried calling

onbeforeunload="function callAjax();"

in &l开发者_如何转开发t;body>. But it also calling at the time when I am using

window.close()

to close popups.

PS: I don't want to use jQuery.


Wow thanks @Andrew it works I have created multiple pages as the below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document 3 </TITLE>
  <script type="text/javascript" for="window" src="tools.js" event="onunload"/>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>

 <BODY>

 </BODY>
</HTML>

Created a tools.js

alert('I am getting closed yipeeee');

Whenever I am closing the window actually tools.js is being called for all the pages

Minimum changes required ie

<script type="text/javascript" for="window" src="tools.js" event="onunload"/>

Thanks for the help.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号