Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have coding for on mousemove event.But it working well in IE and firfox but not in Google chrome........

MY code is here.....
C#
var mouse;
             function storeMouse(e) {
                 if (!e) e = window.event;
                 mouse = { clientX: e.clientX, clientX: e.clientY };
             }

             function test(e) {
//                 debugger;
                 alert(mouse.clientX);
                 if (mouse.clientX < 150) {
                     var agree = confirm("Are you sure to leave this page");
                     if (!agree) {
                         return false;
                     }
//                     else {
//
//                     }
                 }
             }
<body onbeforeunload="test(event);" onmousemove="storeMouse(event);">


Can anyone help me.....

Thanks....
Posted
Comments
Pablo Aliskevicius 9-Apr-12 1:34am    
Please clarify about "not working": is the event firing at all?
The function storeMouse, as posted, has a typo: does this typo avoid compilation?

1 solution

hi,

if your requirement is to alert the user on the browser window close then it can also be achieved like this:

C#
var inFormOrLink;
      $('a').live('click', function () { inFormOrLink = true; });
      $('form').bind('submit', function () { inFormOrLink = true; });

      $(window).bind("beforeunload", function () {
          return inFormOrLink || confirm("Do you really want to close?");
      });


I tested it in both FireFox and Chrome
 
Share this answer
 
Comments
vivekx2 9-Apr-12 2:05am    
Thanks for your support....

I pasted your coding in my javascript. It need to call inside body or not...Please clear my doubt...
tanweer 9-Apr-12 6:24am    
no no, you just need to past the above code in your Head section

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900