Simple iPhone5 detection with JavaScript

It’s really simple, just use this function:

function isIphone5(){
	function iOSVersion(){
		var agent = window.navigator.userAgent,
		start = agent.indexOf( 'OS ' );
		if( (agent.indexOf( 'iPhone' ) > -1) && start > -1)
			return window.Number( agent.substr( start + 3, 3 ).replace( '_', '.' ) );
		else return 0;
	}
	return iOSVersion() >= 6 && window.devicePixelRatio >= 2 && screen.availHeight==548 ? true : false;
} 

Now simply call isIphone5() which will return true if:

  • The device is an iPhone
  • and if iOS version is at least 6
  • and if the device has a retina display
  • and if the screen has a height of 548px

These conditions (currently) only apply to iPhone5.

If the user is not on iPhone5 the method will return false.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>