admin管理员组文章数量:1410717
i read some topics but they are was not helpfully
i have 4 script like
<script src=".min.js"></script>
<script src=".js"></script>
<script src=".js"></script>
<script src=".js"></script>
I don't want to load these scripts on mobile devices so if my window width smaller then 780px i don't want my device will load these scripts.
how it can be possible?
i read some topics but they are was not helpfully
i have 4 script like
<script src="http://kleaz./fsc/three.min.js"></script>
<script src="http://kleaz./fsc/Projector.js"></script>
<script src="http://kleaz./fsc/CanvasRenderer.js"></script>
<script src="http://kleaz./fsc/me.js"></script>
I don't want to load these scripts on mobile devices so if my window width smaller then 780px i don't want my device will load these scripts.
how it can be possible?
Share Improve this question asked Apr 18, 2016 at 8:23 Cihan ZenginCihan Zengin 1032 silver badges12 bronze badges 3-
You can load
scripts
asynchronously...Search about it.. Loading them with conditions will help! – Rayon Commented Apr 18, 2016 at 8:24 - Aka, turn your logic around. Only load those script when the windows bigger than 780. You can dynamically add scripts by making a new script tag and inserting it into the body after setting its src. – Shilly Commented Apr 18, 2016 at 8:25
- Surely this is a duplicate. Simply detect screen width, and if 780 or less, don't load the scripts. – RobG Commented Apr 18, 2016 at 8:30
2 Answers
Reset to default 4Only load the scripts if the screen size is greater than 780px, something long the lines of:
if (window.screen.width > 780) {
document.write(
'<script src="http://kleaz./fsc/three.min.js"><\/script>' +
'<script src="http://kleaz./fsc/Projector.js"><\/script>' +
'<script src="http://kleaz./fsc/CanvasRenderer.js"><\/script>' +
'<script src="http://kleaz./fsc/me.js"><\/script>'
)
}
Though you may want to use DOM methods to add the script elements rather than doucment.write.
Try your scripts in following code:
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
if (!isMobile()) {
//place script you don't want to run on mobile here
//TRY YOUR SCRIPT AS FOLLOWING WAY!!!
document.write('<script src="http://kleaz./fsc/three.min.js"></script>');
document.write('<script src="http://kleaz./fsc/Projector.js"></script>');
document.write('<script src="http://kleaz./fsc/CanvasRenderer.js"></script>');
document.write('<script src="http://kleaz./fsc/me.js"></script>');
}
本文标签: javascriptHow to disable some js scripts on mobile devicesStack Overflow
版权声明:本文标题:javascript - How to disable some js scripts on mobile devices - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744825040a2627009.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论