I need to execute the code when the client leads the cursor outside the document (as if he wants to close), but not when closing the tab, namely when the cursor leads.
2 answers
onmouseout - does not work. Found another solution, track the mouse cursor when mouseY is less than zero, execute the code
ns4 = (document.layers)? true:false ie4 = (document.all)? true:false function init() { if (ns4) {document.captureEvents(Event.MOUSEMOVE);} document.onmouseout=mousemove; } function mousemove(event) { var mouse_x = y = 0; if (document.attachEvent != null) { mouse_x = window.event.clientX; mouse_y = window.event.clientY; } else if (!document.attachEvent && document.addEventListener) { mouse_x = event.clientX; mouse_y = event.clientY; } status="x = " + mouse_x + ", y = " + mouse_y; if(mouse_y<=0){console.log('Всё ок')} } init() - If you showed your code, it would be easier to understand which solution is right for you. I would be grateful if in your answer you explain why it does not work? this will help those who will look for a solution to their problems in the future - L. Vadim
- oneie4? Seriously? :) - Grundy
- @Grundy onmouseout - supported by all browsers :))))) - L. Vadim
- Pay attention. that in the code, although you called the mousemove function you use it as an
onmouseouthandler - Grundy - @ L.Vadim in my case, if you hang the handler on the body, it will work when you hover on other elements (at least I had it in chrome). - G.Denis
|
If you want to use the code after the mouse cursor has gone beyond the object, then simply write the following in the element:
<div onmouseout="pasha_function();">Lorem ipsum</div> - If there are other elements inside the div, it will work more often than necessary - andreymal
- Can you give an example? - L. Vadim
- Yes, even just
<div onmouseout="alert(0)"><span>f</span><span>o</span><span>o</span><span>b</span><span>a</span><span>r</span></div>:) - andreymal - @andreymal everything works for me. how to. in all bravserah. Paint the diva in color and check it out - L. Vadim
- And you move the cursor along the entire contents of the foo block, but without removing the cursor from it - nichrome does not work in all browsers) - andreymal
|
<body onmouseleave="alert('leave!');">it works fine for me - andreymal