I have a click event on window load like so :
function myFunction(){
document.getElementById('myEl').click(); // works on desktop, not on mobile
}
window.onload = myFunction;
As mentioned, this works on desktop but not on mobile devices. I gathered it was down to mobile handling click events differently. Is that correct ?
I need my element to be 'clicked' on load on all devices, desktop and touch pads (mobiles etc).
I have a click event on window load like so :
function myFunction(){
document.getElementById('myEl').click(); // works on desktop, not on mobile
}
window.onload = myFunction;
As mentioned, this works on desktop but not on mobile devices. I gathered it was down to mobile handling click events differently. Is that correct ?
I need my element to be 'clicked' on load on all devices, desktop and touch pads (mobiles etc).
Share Improve this question asked Nov 15, 2016 at 16:17 thatOneGuythatOneGuy 10.7k9 gold badges58 silver badges92 bronze badges 7-
1
Did you try
.trigger("click")
? – Praveen Kumar Purushothaman Commented Nov 15, 2016 at 16:17 - @PraveenKumar yeah just implemented that, works on desktop, not on mobile :/ – thatOneGuy Commented Nov 15, 2016 at 16:20
- @PraveenKumar is window.onload the correct way to start a function on load on mobile devices too do you know ? – thatOneGuy Commented Nov 15, 2016 at 16:28
-
Is it OK if you get the solution using
jQuery
? – AsgarAli Commented Nov 15, 2016 at 16:38 - @thatOneGuy That's right... Nothing wrong in it. – Praveen Kumar Purushothaman Commented Nov 15, 2016 at 16:39
1 Answer
Reset to default 5function myFunction() {
$("#myEl").trigger('click');
$("#myEl").trigger('touchstart');
}
window.onload = myFunction;
For touch event, visit below link.
https://developer.mozilla/en-US/docs/Web/Events/touchstart
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742335809a4424625.html
评论列表(0条)