simulating a mouseclick

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • daveyand

    #1

    simulating a mouseclick

    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

  • VK

    #2
    Re: simulating a mouseclick


    daveyand wrote:
    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.elemen tFromPoint(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/elementfrompoin t.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.codingforum s.com/showthread.php? t=21674>

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

    Comment

    • Sym

      #3
      Re: simulating a mouseclick


      VK wrote:
      daveyand wrote:
      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?
      Perhaps you can have a onMouseOver event assigned to each anchor which
      then calls the appropriate script function.



      rgds
      Symeon.

      Comment

      • daveyand

        #4
        Re: simulating a mouseclick

        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.elemen tFromPoint(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 :)

        Comment

        • VK

          #5
          Re: simulating a mouseclick


          Sym wrote:
          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.

          Comment

          • ASM

            #6
            Re: simulating a mouseclick

            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

            Comment

            • daveyand

              #7
              Re: simulating a mouseclick



              On Nov 7, 11:53 am, "VK" <schools_r...@y ahoo.comwrote:
              Sym wrote:
              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.
              Good point :)

              Comment

              • Richard Cornford

                #8
                Re: simulating a mouseclick

                VK wrote:
                Sym wrote:
                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.
                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.

                Comment

                Working...