仅在桌面站点上执行jQuery - 不要在Mobile上执行jQuery [英] Execute jQuery only on desktop site - Don't execute jQuery on Mobile

查看:95
本文介绍了仅在桌面站点上执行jQuery - 不要在Mobile上执行jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让这个代码只用于桌面 - 基本上我想为移动设备禁用这个jQuery。我在这里尝试了几种方法,但我无法让它们工作 - 但我不是一个人,所以它可能是我实现它们的方式。

I am trying to get this code to function only a desktop - basically i want to disable this jQuery for mobile devices. I tried a few ways recommended here, but I couldnt get them to work - but I'm not ajavascript person so it could have been the way I was implementing them.

<script type="text/javascript">
jQuery(document).ready(function($){
$('.gilidPanel-opener a').click();
});
</script>


推荐答案

您可以检查当前浏览器的用户代理字符串使用 navigator.userAgent

You can check the user agent string for the current browser by using navigator.userAgent:

var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;

jQuery(document).ready(function($){
    if(!isMobile) {
        $('.gilidPanel-opener a').click();
    }
});

这篇关于仅在桌面站点上执行jQuery - 不要在Mobile上执行jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆