The Easiest Way to Save and Share Code Snippets on the web

Check if browser is mobile safari (iPhone)

html4strict | by: fplag

last edit: Aug, 8th 2009 | jump to bottom

<html>
<head>
<script type="text/javascript">
	function isiphone(){
	 	return ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) != null;
	}
 
	function init(){             
 
		if (isiphone()){
			document.getElementById("result").innerHTML = "true";
		}else{
			document.getElementById("result").innerHTML = "false";
		}
	}
</script>
 
</head>
 
<body onload="init()">
 
	<p>iPhone or iPod? <strong><span id="result"></span></strong></p>
 
</body>   
453 views