• 腾讯首页分辨手机端与pc端代码


    腾讯首页分辨手机端与pc端代码

      自己在做网页的时候在腾讯网首页借鉴的代码.

      代码:

     1 <!-- 移动适配JS脚本 -->
     2     <script type="text/javascript">
     3         if (window.location.toString().indexOf('pref=padindex') != -1) {
     4         } else {
     5             if (/AppleWebKit.*Mobile/i.test(navigator.userAgent) || /(Android.*Mobile.+).+Gecko.+Firefox/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))) {
     6                 if (window.location.href.indexOf("?mobile")<0){
     7                     try {
     8                         if (/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
     9                             window.location.href="https://www.xiyixu.top/mobile_index.html";
    10                         } else if (/iPad/i.test(navigator.userAgent)) {
    11                             //window.location.href=""
    12                         } else {
    13                             window.location.href="https://www.xiyixu.top/simple_index.html"
    14                         }
    15                     } catch (e) {}
    16                 }
    17             }
    18         }
    19     </script><!--[if !IE]>|xGv00|6a478dd274c352466ec1a24404f6e978<![endif]-->

    见解:

    if (/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent))
    此句判断打开网页的设备是否为Android|Windows Phone|webOS|iPhone|iPod|这些设备,如果是,则指向一个新的网页,如果不是则继续执行.

    代码源自腾讯网首页

    2018年10月9日18:7:16

  • 相关阅读:
    归类常用控件GroupBox、TabControl、Expander
    ScrollViewer控件
    捕获鼠标位置
    5、标记拓展
    如何实现文件增量同步——算法
    常用的 Nand Flash 指令如下:
    Consistent Hashing算法
    循环冗余检验 (CRC) 算法原理
    yaffs2根文件系统的构建过程
    linux内存管理之uboot第一步
  • 原文地址:https://www.cnblogs.com/lygz/p/9761954.html
Copyright © 2020-2023  润新知