jsPC和移动端链接分离js判断代码

 

移动端

<script>
function
uaredirect() { if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { window.location.href = "http://m.vccoo.com/v/a9e23c"; } } uaredirect();
</script>

js 判断是否为IE浏览器

条件注释,不适用于IE10及以上版本,无效果

<!--[if IE]>
(~ ̄▽ ̄)~
<![endif]-->

所以只能使用js判断

适用于所有大于ie 6版本的浏览器(IE7、8、9、10等),包括Edge浏览器

<script>
function isIE () {
   var userAgent = navigator.userAgent.toLowerCase();
   return (userAgent.indexOf('msie') != -1 || userAgent.indexOf('trident') != -1 || userAgent.indexOf("edge") != -1) ? true : false;
}
if(isIE()){
    console.log(1);
}
</script>

 

其它参考

一篇文章让你搞懂JS懒加载(lazyload): https://blog.csdn.net/qq_41893551/article/details/103180032

  

posted @ 2018-01-26 15:01  绝技小嗨皮  阅读(185)  评论(0)    收藏  举报
Title