最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript to detect iPhone web browser - Stack Overflow

programmeradmin4浏览0评论

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
Add a comment  | 

2 Answers 2

Reset to default 15
if (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')) {

  }
?>
发布评论

评论列表(0)

  1. 暂无评论