Synthetic click on link doesn't follow link

Discussion in 'Javascript' started by Peter Michaux, Jun 4, 2007.

  1. Hi,

    Below is an example of a synthetic click in Firefox. The browser does
    not follow the link. Is that the just the way synthetic clicks work of
    am I doing something wrong? I know the synthetic click occurs because
    if I add an onclick attribute to the link the handler runs. Any ideas?

    Thanks,
    Peter

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en">
    <head>

    <title>synthetic click</title>

    <script type="text/javascript">

    window.onload = function() {
    var el = document.getElementById('myLink');

    var e = document.createEvent("MouseEvents");

    e.initMouseEvent('click', // event type
    true, // can bubble
    true, // cancelable
    window, // abstract view
    0, // detail
    0, // screenX
    0, // screenY
    0, // clientX
    0, // clientY
    false, // ctrl key
    false, // alt key
    false, // shift key
    false, // meta key
    0, // button
    null); // related target

    el.dispatchEvent(e);

    }

    </script>

    </head>
    <body>

    <p><a id="myLink" href="http://www.yahoo.com">myLink</a></p>

    </body>
    </html>
    Peter Michaux, Jun 4, 2007
    #1
    1. Advertising

  2. On Jun 3, 8:42 pm, Peter Michaux <> wrote:
    > Hi,
    >
    > Below is an example of a synthetic click in Firefox. The browser does
    > not follow the link. Is that the just the way synthetic clicks work of
    > am I doing something wrong? I know the synthetic click occurs because
    > if I add an onclick attribute to the link the handler runs. Any ideas?



    After some more research I discovered that this is a known problem.
    The solution is just to manually set the location.href property.

    Thanks for reading.

    Peter
    Peter Michaux, Jun 4, 2007
    #2
    1. Advertising

  3. Peter Michaux

    -Lost Guest

    Peter Michaux wrote:
    > On Jun 3, 8:42 pm, Peter Michaux <> wrote:
    >> Hi,
    >>
    >> Below is an example of a synthetic click in Firefox. The browser does
    >> not follow the link. Is that the just the way synthetic clicks work of
    >> am I doing something wrong? I know the synthetic click occurs because
    >> if I add an onclick attribute to the link the handler runs. Any ideas?

    >
    >
    > After some more research I discovered that this is a known problem.
    > The solution is just to manually set the location.href property.


    Can you provide the location of this solution?

    --
    -Lost
    Remove the extra words to reply by e-mail. Don't e-mail me. I am
    kidding. No I am not.
    -Lost, Jun 5, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce .J Sam
    Replies:
    2
    Views:
    425
    Bruce .J Sam
    Apr 3, 2005
  2. Roland Schwarz

    How to make a "synthetic" lvalue?

    Roland Schwarz, May 19, 2008, in forum: C++
    Replies:
    0
    Views:
    300
    Roland Schwarz
    May 19, 2008
  3. synthetic properties

    , Sep 2, 2008, in forum: Python
    Replies:
    2
    Views:
    670
    Bruno Desthuilliers
    Sep 2, 2008
  4. chad
    Replies:
    14
    Views:
    562
    Arnaud Delobelle
    Oct 13, 2010
  5. Fokke Nauta

    Html page doesn't follow CSS sheet

    Fokke Nauta, Jan 25, 2011, in forum: HTML
    Replies:
    14
    Views:
    699
    Fokke Nauta
    Jan 25, 2011
Loading...

Share This Page