views:

56

answers:

1

I'm curious about if it's possible to make an onmouseover event fire when page loads with the mouse over the image in question? I don't want to move the mouse anything (hence using mousemove won't solve anything).

I have checked these earlier posts:

http://stackoverflow.com/questions/2903068/jquery-trigger-mouseover-function-when-page-loads-with-the-mouse-over-the-element

and

http://stackoverflow.com/questions/1521443/detect-if-mouse-is-over-an-element-when-page-loads-with-javascript

The first suggests mousemove which requires moving the mouse. Another answer suggests the use of JQuery and .load() and .hover() which basically make use of the mouseover and mouseout events in Javascript, hence not bringing anything new to the question (nothing can be done in JQuery that can't be done in simple Javascript right?)

The second post suggests, apart from mousemove, a function which via CSS display property makes the image disappear after it's loaded and then reappear at the same spot, thus according to the poster, making the mouseover event fire. However, it doesn't fire when I do it this way, neither in the current version of Firefox (3.6) nor the 3.0 version which the tester used (I don't know if he really got it to work or not but I believe I understood him correctly). The last poster to the second thread suggests it can't be done because the page needs to know where the cursor is positioned and it can't do that if you don't move the mouse, maybe that's the true answer?


In Explorer 8, this thing is fixed somehow because for example a NEXT button continues to show it's onmouseover image instead of switching back to its "off"-button when the page reloads and the mouse rests over the same image without moving. However, none of the other browsers have this feature.

I realize this problem can easily be fixed by using Javascript and not reloading the entire page, thus keeping the onmouseover image on the button being on a part of the page that is not renewed, but I'm curious as I said about whether it's possible without this.

Also, mixing with focus and setting the onfocus attribute in the anchor tag surrounding the image can also fix things but not entirely since then the risk would now be that the mouse cursor was repositioned during the load of the new page and then keeping the focus via the anchor tag on the pressed button to make it use its "on"-button would be a bad idea.


So, is there any way to detect whether the mouse is positioned over an image when the page loads without the mouse moving even a pixel or is this not possible?

A: 

I do not believe that this is possible, since the Browser determines the mouseover event based on mousemoves. The CSS :hover pseudo-class does not fire in my tests either.

elusive
I believe you're right... would be nice to get this confirmed by a few others though and some brief explanation about how they managed to have this feature in Explorer 8 :) Thanks!
fast-reflexes