phpmywind网站PC端跳转手机端如何实现
1、使用的代码是:(基本原理就是检测访问端,然后用if语句判断是否跳转)<script type="text/javascript"> function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if ((bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){ window.location.href='http://www.xndxdl.com/mobile'; } } browserRedirect(); </script>首先,在网站根目录下的index.php中加入程序代码,测试不能自动跳转手机网页。测试失败!具体原因我也不清楚。PC端能访问,手机端不能实现跳转。(注意:代码块需要加在head之前。其次,我的手机代码新建文件名:mobile)
2、经过分析。手机访问phpmywind源码网站总是跳转到http://www.xndxdl.com/4g.php,页面。然后我继续修改4g.php页面,发现手机访问还是失败。
3、再次分析原因。发现原程序存储手机代码的地址是:根目录\templates\default\mobile,分析发现,在访问手机端时,程序跳转的顺序是:主页面index.php——跳转到\templates\default\mobile\index.php——在跳转到\templates\default\mobile\nav.php(在程序代码里href="4g.php">首 页)。因此需要在里面进行修改。
4、根据上面分析,有两种方式:第一种\templates\default\mobile\nav.php中的href="4爿讥旌护g.php"直接改成需要的跳转地址(例如:href="mobile/index.html")。另外一种直接在\templates\default\mobile\index.php程序的head之前加入跳转代码:<script type="text/javascript"> function browserRedirect() { var sUserAgent = navigator.userAgent.toLowerCase(); var bIsIpad = sUserAgent.match(/ipad/i) == "ipad"; var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; if ((bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){ window.location.href='http://www.xndxdl.com/mobile'; } } browserRedirect(); </script>最终成功实现各个端口可以适配跳转。原创发帖不易,请点赞!希望对小白有用!