简体   繁体   English

如果在移动设备上查看脚本,如何禁用或隐藏脚本在我的网站上运行?

[英]How can I disable or hide a script from running on my site if being viewed on a mobile device?

I know this is a simple one but, I'm just not good enough with JavaScript to get it right. 我知道这很简单,但是我对JavaScript不够了解。

I have a script I'm using (skrollr.js) to create some animated parts and I do not want this script to run when the site is hit on a mobile device. 我有一个正在使用的脚本(skrollr.js)创建一些动画部件,并且当在移动设备上点击该网站时,我不希望此脚本运行。

The script is simply: 该脚本很简单:

<script type="text/javascript" src="/scripts/skrollr.min.js"></script>
<script type="text/javascript">
    var s = skrollr.init();
</script>

It works great on desktop but is funky on mobile devices so, I've decided to just disable it all together on mobile. 它在台式机上效果很好,但在移动设备上却很时髦,因此,我决定只在移动设备上全部禁用它。

I don;t want to redirect to a different page or anything... I simply just don;t want the script to run on mobile. 我不想重定向到其他页面或其他任何内容……我只是不想让脚本在移动设备上运行。 How can I make that happen? 我该如何实现?

Thanks. 谢谢。

Detecting a mobile browser Please check this post. 检测移动浏览器请检查这篇文章。 just put your script you want to run in the if statement. 只需将要运行的脚本放在if语句中即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM