simulating a mouseclick

D

daveyand

Is there a way in javascript to trigger the clicking of the left mouse
button.

Basically i have a floating div that is translucent (40% opacity) this
div covers the whole screen. when a user clicks on this div it
disappears. What i would like is if the mouse happens to be over a
link then that link should trigger.

I imagine i can do a long way which'll involve where is the mouse now,
what anchor is there, if its a link then set the location to this href.


But that seems like alot of work, can i not just simulate a click of
where the mouse is?

Hope people understand what i mean.

Andy
 
V

VK

daveyand said:
Is there a way in javascript to trigger the clicking of the left mouse
button.

Basically i have a floating div that is translucent (40% opacity) this
div covers the whole screen. when a user clicks on this div it
disappears. What i would like is if the mouse happens to be over a
link then that link should trigger.

I imagine i can do a long way which'll involve where is the mouse now,
what anchor is there, if its a link then set the location to this href.


But that seems like alot of work, can i not just simulate a click of
where the mouse is?

IE has an absolutely wonderful method document.elementFromPoint(x,y) So
all you need to do is to use this method with the received click coords
(from clicking your DIV) and if there is a link at that point you are
using link's click() method on it.
<http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/elementfrompoint.asp>

Unfortunately no one other rival bothered so far to implement it, so
you have to code it manually somehow; see for instance:
<http://www.codingforums.com/showthread.php?t=21674>

There can be more elegant and effective ways I don't know about.
 
S

Sym

Perhaps you can have a onMouseOver event assigned to each anchor which
then calls the appropriate script function.



rgds
Symeon.
 
D

daveyand

Sadly i dont think the site will allow me to change the html itself.
(This div is a settings window that has been added on) So Sym sadly
wont be able to do that :(

VK i like your solution, i didnt know about the function you mentioned.
I love it, and wish, as you said, someone else had made something
similar.

Will look into seeing what i can do about that. So i guess i can
simply do something like

var oelement = document.elementFromPoint(iX, iY);
if(oelement == "A") {

location.src = oelement.src;

}

Or words to that effect?

Will look into making a FF and other browser version, or rather,
stealing the one you mentioned :)
 
V

VK

Sym said:
Perhaps you can have a onMouseOver event assigned to each anchor which
then calls the appropriate script function.

That will not work because with DIV hover the entire page all mouse
events will be sent to that DIV, not to elements below it.
 
A

ASM

daveyand a écrit :
Is there a way in javascript to trigger the clicking of the left mouse
button.

Basically i have a floating div that is translucent (40% opacity) this
div covers the whole screen. when a user clicks on this div it
disappears. What i would like is if the mouse happens to be over a
link then that link should trigger.

I imagine i can do a long way which'll involve where is the mouse now,
what anchor is there, if its a link then set the location to this href.


But that seems like alot of work, can i not just simulate a click of
where the mouse is?

Hope people understand what i mean.

Nope !

perhaps could you see stopPropagation and its brother for Ie ?

google -> IE event propagation
 
R

Richard Cornford

VK said:
That will not work because with DIV hover the entire page all mouse
events will be sent to that DIV, not to elements below it.

When the DIV is removed following the click the mouse will be over some
other element and that element likely will get a mouseover event
triggered on it. So in principle the link hovered over by the mouse at
the point when the DIV is hidden (when it is clicked) is the/a link
that generates a mouseover event before the first mouseout event on any
element.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top