文章摘要
这篇文章描述了一个双端重定向的JavaScript脚本,用于根据用户的设备类型(移动设备或PC)自动重定向页面。代码通过检测`navigator.userAgent`来区分移动设备用户和普通用户。如果是移动设备用户(如Android、iPad、iPhone、iPod等),则会将包含`//www.`的URL转换为包含`//m.`的URL;如果是PC用户,则反之,将包含`//m.`的URL转换为包含`//www.`的URL,从而实现统一的访问入口。该脚本旨在简化用户浏览体验,提升网站兼容性。
if(window!=top){top.location.href=_window.location.href;} var shouji = navigator.userAgent.match(/Android|iPad|iPhone|iPod/i) != null; var url = _window.location.href; var host = _window.location.host; if(shouji){ if(url.indexOf('//www.') > -1){ var wwwurl = url.replace("//www.","//m."); location.href= wwwurl; } }else{ if(url.indexOf('//m.') > -1){ var wwwurl = url.replace("//m.","//www."); location.href= wwwurl; } }