0

I'm using third-party javascript library and I want to emulate clicking on some element. $('#element').trigger('click'); And it works, but when I try this at my Android device, it doesn't work. I don't know how that third-party library works, but when I tap on the element, it fires, how can i detect which event is fired and call it from the javascript? Thanks!

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
Volodymyr
  • 1,557
  • 2
  • 14
  • 21
  • It looks like you're using jQuery. `"I don't know how that third-party library works"` Don't you think you should find out? – Charlie Jun 18 '13 at 14:31
  • Yes, I think I won't be able to find that. It contains 6000 lines of code. http://we.tl/SfqKUs6Rae (galleria.io) – Volodymyr Jun 18 '13 at 14:38
  • You don't need to post 6000 lines of code to show us your code. Only show us what's important... furthermore, that's a lot of code. Consolidate! Also, it's frowned upon to ask for potential helpers to download your entire JS file from an unknown file sharing website. – Charlie Jun 18 '13 at 14:41
  • Sorry.... You can download the plugin form the official website - http://galleria.io/download/ Ok, what is important: the plugin attaches some actions to some elements.. So, it attaches opening the slideshow on clicking on some element. I want to emulate clicking, so I wrote $('#element').trigger('click'); Click is binded by the library plugin and I call it from the JS... And it works. But it doesn't work on my Android. So, I think on mobile device not click event, but some another is binded. How to know which one? – Volodymyr Jun 18 '13 at 14:46
  • Why don't you just change it so that the function is called `onLoad`, instead of `onClick`? – Charlie Jun 18 '13 at 14:47
  • Ok look, the third party library is image gallery + slideshow plugin. My aim is to launch the slideshow automatically. Currently it is being launched by user's clicking on the photo. So, I emulate clicking by using $('#element').trigger('click'); code. And it works. But on mobile devices it doesn't work, because click event is not being fired. On mobile device if I tap on the element, the slideshow starts, but with the code $('#element').trigger('click'); it doesn't. How to detect which event is being fired when users clicks on the element? – Volodymyr Jun 18 '13 at 14:58
  • That's great and all, but depending on the script, there should be a way to run the slideshow when the page loads, or from within another function. Then you don't need to trigger the click of anything. Look at the documentation for the scripts you're using, and find a way to run the slideshow without having to click on an element. – Charlie Jun 18 '13 at 15:02
  • Ok, but is there a way to detect event fired at javascript? – Volodymyr Jun 18 '13 at 15:06
  • Googling exactly what you typed: http://stackoverflow.com/questions/3787555/how-to-find-out-which-javascript-events-fired – Charlie Jun 18 '13 at 15:12

1 Answers1

1

It is most likely that the plugin is using touchstart event when on mobile. However, this may not be the same for all mobile devices, so it would not be best to rely on that fact.

There is no easy way to detect — from a JavaScript point of view — what event has been applied to which element (in native terms), at least as far as I know. Different versions of jQuery do store the events that have been applied using that instance of jQuery, which you can access via the .data() method. However this is not standardised and jQuery keep changing the way they are stored, so it is unreliable.

Your best bet is to find some kind of plugin that works for your browser, I have a number of plugins tied into Firebug (for Firefox) which help with a number of jQuery queries... however, getting these to feed back from mobile would be tricky and I have not tried anything like this myself.

Community
  • 1
  • 1
Pebbl
  • 34,937
  • 6
  • 62
  • 64