Determine whether the mobile user opens the page with Android or iOS, and returns the result via AJAX to the URL interface, passing it back

Source: Internet
Author: User

First determine whether the page is Android or iOS, and then use Ajax to return the results via the interface URL, recorded in the log log to count the number of Android and iOS users accessing the page (data statistics)

<script type= "Text/javascript" >window.onload=function() {//page is executed immediately after loading varU =navigator.useragent; varisandroid = U.indexof (' Android ') >-1 | | U.indexof (' Adr ') >-1;//android Terminal        varIsios =!! U.match (/\ (i[^;] +;( U;)? Cpu.+mac OS x/);//ios Terminal        if(Isandroid = =true){            <!--alert (' Whether it's Android: ' +isandroid '); -$.ajax ({type:"POST", URL:"Interface Address",//interface address of the request data: {"SystemType": "Android"},//android if a constant must be quoted, the variable does not need to be quoted DataType:"JSON", Success:function(msg) {alert (msg); }, Error:function(Error) {alert ("Android Submission failed");        }            }); }Else if(Isios = =true){            <!--alert (' is iOS: ' +isios '); -$.ajax ({type:"POST", URL:"Interface Address", data: {"SystemType": "ios"}, DataType:"JSON", Success:function(msg) {alert (msg); }, Error:function(Error) {alert ("iOS submission failed");        }            }); }    }</script>

Determines whether the mobile user opens the page with Android or iOS and returns the results to the URL interface via Ajax, passing it back

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.