Javascript 编辑此代码以根据屏幕大小而不是设备大小重定向到移动站点

Javascript 编辑此代码以根据屏幕大小而不是设备大小重定向到移动站点,javascript,Javascript,这个问题说明了一切,下面是我目前的重定向代码,但我想编辑它,使它重定向屏幕大小,而不是设备。它仍然需要设置cookie,这样用户就可以回到主站点 <script type="text/javascript"> var mfp_url='http://mob.visitorconversions.co.uk'; var mfp_host_name=document.location.hostname; var mfp_request_uri=document.location.path

这个问题说明了一切,下面是我目前的重定向代码,但我想编辑它,使它重定向屏幕大小,而不是设备。它仍然需要设置cookie,这样用户就可以回到主站点

<script type="text/javascript">
var mfp_url='http://mob.visitorconversions.co.uk';
var mfp_host_name=document.location.hostname;
var mfp_request_uri=document.location.pathname;
var  mfp_no_mobile=location.search;
var mfp_cookie=document.cookie;

function mf_detect(){var  mfp_ua=navigator.userAgent.toLowerCase();var mfp_devices=['vnd.wap.xhtml+xml','sony','symbian','nokia','samsung','mobile','windows ce','epoc','opera mini','nitro','j2me','midp-','cldc-','netfront','mot','up.browser','up.link','audiovox','blackberry','ericsson','panasonic','philips','sanyo','sharp','sie-','portalmmm','blazer','avantgo','danger','palm','series60','palmsource','pocketpc','smartp hone','rover','ipaq','au- mic','alcatel','ericy','vodafone','wap1','wap2','teleca','playstation','lge','lg- ','iphone','android','htc','dream','webos','bolt','nintendo'];

for(var i in mfp_devices) {if(mfp_ua.indexOf(mfp_devices[i])!=-1){return true}}}if(mfp_no_mobile!='? nomobile=1'&&mfp_cookie.indexOf('mfp_no_mobile')==-1) {mfp_is_mobile=mf_detect();if(mfp_is_mobile){window.location=mfp_url+"? h="+mfp_host_name+"&r="+mfp_request_uri}}else{if(mfp_cookie.indexOf('mfp_no_mobile')!=-1)  {}else{mfp_cookie_expires=new   Date();mfp_cookie_expires.setTime(mfp_cookie_expires.getTime()+1000*60*60*24);document.cook    ie="mfp_no_mobile=1; expires="+mfp_cookie_expires.toGMTString()+"; path=/;"}}
</script>

var mfp_url=http://mob.visitorconversions.co.uk';
var mfp_host_name=document.location.hostname;
var mfp_request_uri=document.location.pathname;
var mfp_no_mobile=location.search;
var mfp_cookie=document.cookie;
函数mf_detect(){var mfp_ua=navigator.userAgent.toLowerCase();var mfp_设备=['vnd.wap.xhtml+xml','sony','symbian','nokia','samsung','mobile','windowsce','epoc','opera mini','nitro','j2me','midp-','cldc-','netfront','mot','up.browser','up.link','audiovox','blackberry','ericsson','panasonic','philips','sanyo sharp','sie-','portalmm','blazer','dager','avantgo','palm source'spart','smartpocketpc','er’、‘ipaq’、‘au-mic’、‘阿尔卡特’、‘埃里克’、‘沃达丰’、‘wap1’、‘wap2’、‘teleca’、‘playstation’、‘lge’、‘lg-’、‘iphone’、‘android’、‘htc’、‘dream’、‘webos’、‘bolt’、‘任天堂’;
对于(mfp-U设备中的var i)来说(mfp-i的var i在mfp-U设备中的var i在mfp-U设备中的var i在mfp-i在mfp-U设备中的var i在mfp-i在mfp-U设备中的var i在mfp-i在mfp-i在mfp(mfp-U的U U U)设备中的指数)的(mfp-UU.ndexof(mfp设备[i)器件[i)器件[i!!!!!!!!!!!!!!!!!!!1!1!=-1)1)1{{{{{{{返回返回真实{}}}}}}}}}}}}}}}}}}}}若(返回(返回返回返回返回返回真}}}}}}}}}}}}}若(返回)若(返回真实(返回真真(返回返回真真真真的}}}mobile')!=-1{}其他{mfp_cookie_expires=new Date();mfp_cookie_expires.setTime(mfp_cookie_expires.getTime()+1000*60*60*24);document.cook ie=“mfp_no_mobile=1;expires=“+mfp_cookie_expires.togmString()+”;path=/;“}}
使用下面的答案,我现在得出以下结论:

<script type="text/javascript">
var mfp_url='http://mob.visitorconversions.co.uk';
var mfp_host_name=document.location.hostname;
var mfp_request_uri=document.location.pathname;
var  mfp_no_mobile=location.search;
var mfp_cookie=document.cookie;

function mf_detect() {
var MOBILE_WIDTH = 640;
var screenWidth = function() {
    width = null;
    if (window.screen != null) width = window.screen.availWidth;
    if (window.innerWidth != null) width = window.innerWidth;
    if (document.body != null) width = document.body.clientWidth;
    return width;
}
return screenWidth() <= MOBILE_WIDTH;
}

for(var i in mfp_devices) {if(mfp_ua.indexOf(mfp_devices[i])!=-1){return true}}}if(mfp_no_mobile!='? nomobile=1'&&mfp_cookie.indexOf('mfp_no_mobile')==-1) {mfp_is_mobile=mf_detect();if(mfp_is_mobile){window.location=mfp_url+"? h="+mfp_host_name+"&r="+mfp_request_uri}}else{if(mfp_cookie.indexOf('mfp_no_mobile')!=-1)  {}else{mfp_cookie_expires=new   Date();mfp_cookie_expires.setTime(mfp_cookie_expires. getTime()+1000*60*60*24);document.cook    ie="mfp_no_mobile=1; expires="+mfp_cookie_expires.toGMTString()+"; path=/;"}}
</script>

var mfp_url=http://mob.visitorconversions.co.uk';
var mfp_host_name=document.location.hostname;
var mfp_request_uri=document.location.pathname;
var mfp_no_mobile=location.search;
var mfp_cookie=document.cookie;
函数mf_detect(){
var移动_宽度=640;
var screenWidth=函数(){
宽度=零;
如果(window.screen!=null)width=window.screen.availWidth;
如果(window.innerWidth!=null)width=window.innerWidth;
如果(document.body!=null)width=document.body.clientWidth;
返回宽度;
}

return screenWidth()此代码适用于我。如果屏幕分辨率小于MOBILE_WIDTH,它将重定向到http://mob.visitorconversions.co.uk?h=[引用\u主机]&r=[引用\u路径]

选中此项。您可能需要调整结果窗口的大小以查看重定向加载

<script type="text/javascript">    
    var mfp_url = 'http://mob.visitorconversions.co.uk';
    var mfp_host_name = document.location.hostname;
    var mfp_request_uri = document.location.pathname;
    var mfp_no_mobile = location.search;
    var mfp_cookie = document.cookie;

    function mf_detect() {
        var MOBILE_WIDTH = 640;
        var screenWidth = function() {
            width = null;
            if (window.screen != null) width = window.screen.availWidth;
            if (window.innerWidth != null) width = window.innerWidth;
            if (document.body != null) width = document.body.clientWidth;
            return width;
        };
        return screenWidth() <= MOBILE_WIDTH;
    }

    if (mfp_no_mobile != '?nomobile=1' && mfp_cookie.indexOf('mfp_no_mobile') == -1) {
        mfp_is_mobile = mf_detect();
        if (mfp_is_mobile) {
            window.location = mfp_url + "?h=" + mfp_host_name + "&r=" + mfp_request_uri
        }
    } else {
        if (mfp_cookie.indexOf('mfp_no_mobile') != -1) {} else {
            mfp_cookie_expires = new Date();
            mfp_cookie_expires.setTime(mfp_cookie_expires.getTime() + 1000 * 60 * 60 * 24);
            document.cookie = "mfp_no_mobile=1; expires=" + mfp_cookie_expires.toGMTString() + "; path=/;"
        }
    }​
</script>

var mfp_url=http://mob.visitorconversions.co.uk';
var mfp_host_name=document.location.hostname;
var mfp_request_uri=document.location.pathname;
var mfp_no_mobile=location.search;
var mfp_cookie=document.cookie;
函数mf_detect(){
var移动_宽度=640;
var screenWidth=函数(){
宽度=零;
如果(window.screen!=null)width=window.screen.availWidth;
如果(window.innerWidth!=null)width=window.innerWidth;
如果(document.body!=null)width=document.body.clientWidth;
返回宽度;
};

return screenWidth()我试过了,但现在它没有重定向任何内容。谢谢您的尝试!您的问题代码中仍然存在一些错误,因此我发布了完整的代码片段以减少混淆。