简体   繁体   中英

Touch events in JavaScript on Android

I have an HTML page with a div that acts like a momentary on-off switch. It works something like this:

     $('#btn').mousedown(function() {
         startAction()
     })
     $('#btn').mouseup(function() {
         stopAction()
     })
     $('#btn').mouseout(function() {
         stopAction()
     })

This works fine in a regular web browser. But it doesn't work when I load up the page in a WebView under Android. According to this, mousedown events don't work on Android like most people expect them to; so, is there any other way to accomplish this? Basically, what I want is a notification when the user puts a finger down onto the widget, and when the finger is taken away.

I'd prefer to use JQuery, but I don't have to. I'd also prefer a solution that works on other mobile platforms.

If I remember correctly, on Android, the webviews have JS disabled by default and need to be enabled. You can enable them with the document at http://developer.android.com/resources/tutorials/views/hello-webview.html

I think really, you're up to the mercy of the device and the owner as to whether or not the user has javascript enabled.

http://hubpages.com/hub/How-to-enable-disable-JavaScript-on-the-Droid-Android-phone

Hope this helps ~Kevin

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