admin 发表于 2016-11-8 09:44:21

手机访问PC自动跳转WAP

$agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($agent,"NetFront") || strpos($agent,"iPhone") || strpos($agent,"MIDP-2.0") || strpos($agent,"Opera Mini") || strpos($agent,"UCWEB") || strpos($agent,"Android") || strpos($agent,"Windows CE") || strpos($agent,"SymbianOS"))
header("Location:http://wap.xxx.com");

PHP版
----------------------------------------------------------------------------------------
<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("http://m.xxx.com/");</script>

百度js版
----------------------------------------------------------------------------------------
function isWap(){
    var pda_user_agent_list = new Array("2.0 MMP", "240320", "AvantGo","BlackBerry", "Blazer",
                        "Cellphone", "Danger", "DoCoMo", "Elaine/3.0", "EudoraWeb", "hiptop", "IEMobile", "KYOCERA/WX310K", "LG/U990",
                        "MIDP-2.0", "MMEF20", "MOT-V", "NetFront", "Newt", "Nintendo Wii", "Nitro", "Nokia",
                        "Opera Mini", "Opera Mobi",
                        "Palm", "Playstation Portable", "portalmmm", "Proxinet", "ProxiNet",
                        "SHARP-TQ-GX10", "Small", "SonyEricsson", "Symbian OS", "SymbianOS", "TS21i-10", "UP.Browser", "UP.Link",
                        "Windows CE", "WinWAP", "Android", "iPhone", "iPod", "iPad", "Windows Phone", "HTC"/*, "GTB"*/);
        var pda_app_name_list = new Array("Microsoft Pocket Internet Explorer");

        var user_agent = navigator.userAgent.toString();
        for (var i=0; i<pda_user_agent_list.length; i++) {
                if (user_agent.indexOf(pda_user_agent_list) >= 0) {
                        return true;
                }
        }
        var appName = navigator.appName.toString();
        for (var i=0; i<pda_app_name_list.length; i++) {
                if (user_agent.indexOf(pda_app_name_list) >= 0) {
                        return true;
                }
        }

        return false;
}

if(isWap()){
    var currentHref=location.href;
    currentHref=currentHref.replace("www.","m.");
    location.href=currentHref;
}

普通js版

q31630386 发表于 2019-6-3 12:06:49

请问管理。这个是加到哪个文件里呀!
还是每个模板的文件都加一次呀。
跳转对应的页面就把网站地址改成WAP对应网页的链接呀!
求解!

q31630386 发表于 2019-6-3 12:14:06

还有,我的PC站能每个都跳转到WAP的主页,是后台上面有跳转手机站选择。请问这是不是已经有了跳转代码。请问我该如何修改呀!!!
页: [1]
查看完整版本: 手机访问PC自动跳转WAP