JS adaptation to click response on Android and IOS platforms, and jsandroidios Platform
Summary
Recently, a very strange problem was found during the project, that is, the response to the click event. Tests show that for IOS platforms, directly listening to click events may not respond, but there is no problem on Android and PC. Therefore, different listeners on different platforms are implemented by obtaining device information.
IOS listeners
For IOS devices, listening only to the click method may not respond. The solution is to listen to the "touchend click" event.
For Android and PC, you can only listen to click events.
Platform Detection
We use userAgent to detect the Platform
123456789 |
If (/(iPhone | iPad | iPod | iOS)/I. test (navigator. userAgent) {// alert (navigator. userAgent); alert ("iOS");} else if (/(Android)/I. test (navigator. userAgent) {// alert (navigator. userAgent); alert ("Android") ;}else {alert ("PC ");}; |
The above JS Code can detect three platforms.
Implement listening
We can customize the method name, such
12345 |
Function back_click () {$ (". group-names "). show (); $ (". groups: visible "). hide (); $ (this ). hide ();} |
Then implement listening across platforms
123456 |
/* Bind the event */if (/(iPhone | iPad | iPod | iOS)/I. test (navigator. userAgent) {$ (". back "). bind ({"touchend click": back_click});} else {$ (". back "). bind ({"click": back_click });} |
Through the above listening, there will be no problem.
Summary
You can use the above method to implement listeners on different platforms.