美文网首页
判断移动端并跳转到m域名的代码

判断移动端并跳转到m域名的代码

作者: AI视客 | 来源:发表于2018-09-19 22:35 被阅读19次
<script>
    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
    
    window.location.href =window.location.href.replace("www","m");
    } else if (/(Android)/i.test(navigator.userAgent)) {
        window.location.href =window.location.href.replace("www","m");
    } 
  </script>

代码判断了当前环境的UA,如果是移动端,则将当前域名的www替换成m

相关文章

网友评论

      本文标题:判断移动端并跳转到m域名的代码

      本文链接:https://www.haomeiwen.com/subject/nrvwnftx.html