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?
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?
Share Improve this question asked Aug 5, 2012 at 22:02 Satch3000Satch3000 49.4k89 gold badges224 silver badges349 bronze badges 3- Can I ask why? (My Android isn't in the cool kids club?) Many years ago, we tried allowing only certain browsers to view our pages, and we've since decided that was a terrible idea. It's why--to this day--IE claims it's Mozilla. Don't detect browser; feature detect. – josh3736 Commented Aug 5, 2012 at 22:50
- No special reason really – Satch3000 Commented Aug 6, 2012 at 9:34
- For example a page with links to apple store – mplungjan Commented Aug 6, 2012 at 12:04
2 Answers
Reset to default 15if (navigator.userAgent.toLowerCase().indexOf("iphone") ==-1)
location.replace("goaway.html");
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')) {
}
?>