Okay,
so I am working on a web application, that has lots of events, and I need to be able to trigger a function (probably through an event firing). Whenever a user leaves the page with the mouse. I have a timer being triggered every x milliseconds and I want to be able to cancel this interval when the users mouse leaves the page.
I have tried the onmouseout, onblur on the window, document, body and the web application division (note the web application div covers 100% of the document).
None of these work, I also tried triggering the event when the mouse got within 5 pixels of the edge of the document, however this was not reliable and even if it was, Its not really what I want.
*also note this only has to work with Google Chrome.
Cheers, Josh
5 2434
I don't know how you're linking your function to your event, but with addEventListener() I've found you have to use mouseout instead of onmouseout (analogue for the other events).
I am not so concerned with the event code, I have been using these functions I made (doesn't matter if its on<event> or <event>): -
function addEvent(elem, etype, func){
-
if(!etype || etype.constructor != String || !func || func.constructor != Function)return false;
-
if(etype.indexOf("on") == 0)etype.replace("on","");
-
if(window.addEventListener)elem.addEventListener(etype,func,false);
-
else if(window.attachEvent)elem.attachEvent('on'+etype,func);
-
else return 0;
-
return 1;
-
}
-
My question is more a general javascript question, which element or object should I use and which event on that object should I use, if I want to trigger a function when the user moves the mouse outside of the document?
cheers, Josh
@Jezternz
Hi Josh,
It sounds like you want to attach the event listener to the parent of all the other elements. The HTML element from which all the other elements are descended is <body> so I think that is the element you're looking for. Alternatively you could try using the window object.
For the other part of your question, YarrOfDoom gave a good answer: your script will be listening for the mouseout event.
Happy coding!
thanks for replys,
The problem I am having is, when I attach the mouseout event to the window or the body, it does not fire the event unless, I move the mouse off the window very slowly (so it is not really plausable, as often you will move the mouse out of the window in a fast motion). So are there any other ways I can go about this?
cheers, Josh
I would like to apologize, I had something wrong with my code. I was under the impression the onmouseout event would not register on the window object, when infact it works perfectly.
Sorry for any time I wasted, Josh
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mat |
last post by:
How can I detect when a link has been clicked but the new page is
still in the process of loading? The document.location.href property
still displays the current location (understandably) not the...
|
by: red |
last post by:
mouse events when the mouse is on a "child control"
hi everyone;
my problem:
I have a userControl
in this usercontrol, I have a child control (a button)
when the mouse moves over the...
|
by: Sam |
last post by:
Hi,
I can't figure out how to detect when my mouse cursor leaves a panel
control. It should not trigger the event (or do anything) when the
mouse leave the panel but still is over a control that...
|
by: Iosy |
last post by:
Hi all,
I'm working in a application where I need to detect when the mouse is
inactive outside my form. I mean, I want to detect if the mouse hasn't
move in the last X seconds (2 por example)...
|
by: scott8000 |
last post by:
hi all
Access 2K/2003, Win XP Pro
I need to be able to detect when a subform datasheet is currently
displaying a vertical scrollbar.
I.e if the subform datasheet is showing more records...
|
by: =?Utf-8?B?SGFyZHkgV2FuZw==?= |
last post by:
Hi all,
I created a complex ASPX page, nested inside a master page and Ajax
UpdatePanel. In one of my Javascript function I need to capture mouse
position. I use alert(document.body.scrollTop) to...
|
by: windandwaves |
last post by:
Hi Folk
On one of my sites, I have a reather involved page (searchable map).
When the person leaves the page then all the AJAX generated
information is lost. Is there a way that I can retain...
|
by: kiransasi |
last post by:
hi all,
i m herewith struck with this problem....
check out the following code and lemme know the solution for this....
<html>
<heAD>
<TITLE>WAIT</TITLE>
|
by: yawnmoth |
last post by:
I'm trying to write a script whereby the body background is changed to
back (from white) when the mouse button is held down and kept held
down. When you lift it up, I'd like it to change back to...
|
by: Frank Rizzo |
last post by:
I have a form with a lot of controls on it. How can I detect when the
mouse leaves the form? I've tried wiring up a MouseLeave event for every
single control, but that does not work because those...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |