简体   繁体   中英

How to simulate a click on a element which also results in invoking attached events?

My test case is @ Gmail, I am trying to simulate a click to open the first e-mail with JavaScript.

Actually I did a successful attempt which is done by firing a mousedown event.

But I wonder if there is a generic method to generate "organic" clicks instead of me wasting time on investigating attached events ?

You can just trigger the usual suspects...but other than that, there's no good generic way to simulate a native click from a user (and an actual native click is impossible, for example making an <a> go to it href , without doing the redirect yourself).

Triggering the relevant events to a click for something like gmail would look like this:

$(selector).mousedown().mouseup().click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM