从运行JavaScript中排除iOS
我正在使用一篇文章中的预加载程序。在大多数桌面浏览器中都能很好地工作,但我在iOS上遇到了一些问题 有没有一种方法可以排除运行脚本的iOS设备而不提供其他页面 这是我的代码:从运行JavaScript中排除iOS,javascript,iphone,html,Javascript,Iphone,Html,我正在使用一篇文章中的预加载程序。在大多数桌面浏览器中都能很好地工作,但我在iOS上遇到了一些问题 有没有一种方法可以排除运行脚本的iOS设备而不提供其他页面 这是我的代码: $(document).ready(function () { $("body").queryLoader2({ barColor: "#FFFFFF", backgroundColor: "#000000", percentage: true, ba
$(document).ready(function () {
$("body").queryLoader2({
barColor: "#FFFFFF",
backgroundColor: "#000000",
percentage: true,
barHeight: 1,
completeAnimation: "grow",
minimumTime: 1000
});
});
我无法获取
窗口。由于某些原因,添加了EventListener
以与iOS一起工作。检查Iphone用户代理字符串,并根据该结果有条件地预加载图像。您可以检查用户代理字符串
if(!((navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/iPad/i)))) {
// do non iOS stuff here
}
您的代码看起来像
$(document).ready(function () {
if(!((navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/iPad/i)))) {
$("body").queryLoader2({
barColor: "#FFFFFF",
backgroundColor: "#000000",
percentage: true,
barHeight: 1,
completeAnimation: "grow",
minimumTime: 1000
});
}
});
我还将查看该页面上提供的iOS代码,看看这是否解决了您的问题
window.addEventListener('DOMContentLoaded', function() {
$("body").queryLoader2();
});
这是调用它的动作$(document).ready(函数(){$(“body”).queryLoader2({barColor:#FFFFFF),backgroundColor:#000000,percentage:true,barHeight:1,completeAnimation:“grow”,minimumTime:1000});我应该把脚本转储到哪里?(很抱歉,我对javascript不太在行)由于某种原因,我无法让window.addEventListener与iOS一起工作,它似乎是其中之一。不过,您的代码在排除iOS时效果非常好!您是否尝试了与iOS相关的链接部分的代码?