How to detect IPhone / IPad through JavaScript

December 04, 2013 by Anuraj

.Net ASP.Net Javascript

Here is code snippet which helps to identity IPhone or IPad through JavaScript.

if ((navigator.userAgent.match(/iPhone/i)) ||
    (navigator.userAgent.match(/iPad/i))) {
    //IPhone or IPad
}

And here is the C# snippet for user agent checking.

if (Request.UserAgent.IndexOf("iPhone", StringComparison.CurrentCultureIgnoreCase) >= 0 ||
    Request.UserAgent.IndexOf("iPad", StringComparison.CurrentCultureIgnoreCase) >= 0)
{
    //IPhone / IPad
}

Happy Programming :)

Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub