js判断访问媒体介质

<script type="text/javascript">
  var userAgent = navigator.userAgent.toLowerCase(),
  userTerminal = userAgent.match( /ipad/i ) ||
  userAgent.match( /iphone os/i ) ||
  userAgent.match( /midp/i ) ||
  userAgent.match( /ucweb/i ) ||
  userAgent.match( /android/i );
   
  if( userTerminal == 'ipad' )
  {
  document.write( '<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">' );
  document.write( '<meta name="apple-mobile-web-app-capable" content="yes">' );
  document.write( '<meta name="apple-mobile-web-app-status-bar-style" content="black">');
  }
  else if( userTerminal == 'iphone os' )
  {
  document.write( '<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">' );
  document.write( '<meta name="apple-mobile-web-app-capable" content="yes">' );
  document.write( '<meta name="apple-mobile-web-app-status-bar-style" content="black">' );
  }
  else if( userTerminal == 'midp' )
  {
  document.write( '<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">' );
  document.write( '<meta name="apple-mobile-web-app-capable" content="yes">' );
  document.write( '<meta name="apple-mobile-web-app-status-bar-style" content="black">' );
  }
  else if( userTerminal == 'android' )
  {
  document.write( '<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">' );
  };
  </script>
posted @ 2014-07-16 16:01  安雅然  阅读(266)  评论(0编辑  收藏  举报