简体   繁体   English

删除iPad / iPhone的Javascript

[英]Removing Javascript for iPad / iPhone

I am having trouble with the Jquery scrollto command on iphone and ipads, it keeps flickering every time its used and gets stuck so I have decided to remove the code for these devices but am having trouble doing so. 我在iphone和ipad上使用Jquery scrollto命令时遇到麻烦,每次使用它时都会一直闪烁并被卡住,所以我决定删除这些设备的代码,但这样做有麻烦。 Here is the code I am trying to use to only show the javascript on a decktop browser. 这是我试图用来仅在平台浏览器上显示javascript的代码。

<script type="text/javascript"> // <![CDATA[
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
    document.write = "<meta name=\"viewport\" content=width=1024px, minimum-scale=1.0, maximum-scale=1.0 \/>";
}
else{document.write = "<script type=\"text/javascript\">
$(document).ready(function() {$('.nav').onePageNav({begin: function() {console.log('start');}, end: function() {console.log('stop');}, scrollOffset: 30});});
</script>";} // ]]>
</script>

The dev site can be found here: dev.greendealcumbria.com 您可以在以下位置找到开发人员站点:dev.greendealcumbria.com

Cheers 干杯

To elaborate on my comment, why not just execute the function like below? 为了详细说明我的意见,为什么不执行下面的功能呢? Why dynamically create the script element when you could just execute the script? 为什么只需执行脚本就动态创建脚本元素?

<script type="text/javascript"> // <![CDATA[
if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
    document.write = "<meta name=\"viewport\" content=width=1024px, minimum-scale=1.0, maximum-scale=1.0 \/>";
}else{
$(document).ready(function(){
$('.nav').onePageNav({
begin: function() {
console.log('start');
}, 
end: function() {
console.log('stop');
}, 
scrollOffset: 30;
});
});
}
// ]]>
</script>

Try this. 尝试这个。

var ua = navigator.userAgent.toLowerCase();
if ((ua.indexOf('iphone') != -1) 
     || (ua.indexOf('ipod') != -1) 
     || (ua.indexOf('ipad') != -1)) {
    document.write = "<meta name=\"viewport\" content=width=1024px, minimum-scale=1.0, maximum-scale=1.0 \/>";
}
else{
    $(document).ready(function(){
        $('.nav').onePageNav({
            begin: function() {
                console.log('start');
            }, 
            end: function() {
                console.log('stop');
            }, 
            scrollOffset: 30
        });
    });
}

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

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