Reputation: 49422
I am looking for a way to detect if a page is visited by an iPhone.
What I'm basically looking for is for a way to stop all but iPhone from viewing a specific web page.
Something like...
If Browser !=iPhone then exit;
Is this possible using Javascript?
Upvotes: 5
Views: 10920
Reputation: 178375
if (navigator.userAgent.toLowerCase().indexOf("iphone") ==-1)
location.replace("goaway.html");
Upvotes: 15
Reputation: 1305
if(navigator.userAgent.match(/iPhone/i)) {
...
}
Though i would recommend you to do that before the DOM is loaded, e.g. with PHP:
<?php
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone')) {
}
?>
Upvotes: 3