JS adaptation to click response on Android and IOS platforms, and jsandroidios Platform

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.