I am writing a web application (xhtml, css, js) that also browsed in mobile phones. I want to detect the device is iphone 5 or not!
Do you know a javascript controller for it?
I am writing a web application (xhtml, css, js) that also browsed in mobile phones. I want to detect the device is iphone 5 or not!
Do you know a javascript controller for it?
You could use the CSS3 media query to detect iPhone 5:
@media (device-height: 568px) and (-webkit-min-device-pixel-ratio: 2) {
/* iPhone 5 or iPod Touch 5th generation */
}
I knew this:
if('devicePixelRatio' in window && window.devicePixelRatio == 2 ){
// retina
}
AND (if you need to detect on the server)
You need to check if the user is on an iOS device and has a retina display and if the screen is exactly 548px high.
Just checking for retina+displayHeight is not enough since you might accidently target other operating systems (e.g. Android) that run on devices which also have a high density display and a screen height of 548px.
Just use this script, it'll do what you want: http://www.timo-ernst.net/2013/04/simple-iphone-5-detection-with-javascript/
Now you can apply a flag to your dom tree on startup (in <head></head>
):
<script>if (isIphone5()) $("html").addClass("isIphone5");</script>
If you need to target iPhone5 via css you can now apply styles like this for example:
<style>.isIphone5 .someClass{color:red}</style>