js教程

JS判断网站宽度改变样式或触发事件教程

我的站长站 2022-10-15 人阅读

oWidth为获取的网站宽度,然后判断oWidth宽度数值是否小于某分辨率,如果成立就可以加载改变样式文件或触发事件等等,可以自由发挥了。

<script type="text/javascript">    
 var oWidth = document.documentElement.clientWidth || document.body.clientWidth;    
 if (oWidth < 1024) {}    
 else {    
   window.location.href = "https://www.wdzzz.com/";    
 }    
 window.addEventListener("orientationchange", function () {    
   var oWidth = document.documentElement.clientWidth || document.body.clientWidth;    
   if (oWidth < 1024) {}    
   else {    
     window.location.href = "https://www.wdzzz.com/";      
   }    
 }, false);    
 window.addEventListener("resize", function () {    
   var oWidth = document.documentElement.clientWidth || document.body.clientWidth;    
   if (oWidth < 1024) {}    
   else {    
     window.location.href = "https://www.wdzzz.com/";     
   }    
 }, false);    
</script>


相关推荐
  • JS判断
  • 简单的JS判断用户登录代码

    <!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scal...

    js教程 49 2年前
  • JS判断IE浏览器版本

    简单的原生JS判断IE浏览器版本var DEFAULT_VERSION = 8.0; var ua = navigator.userAgent.toLowerCase(); var isIE = ua.indexOf("msie")>-1; var safariVersion; if(isIE){ safariVersion = ua.match(/msie ([\d.]+)/)[1]; } if(safariVe...

    js教程 154 4年前
  • JS判断input file图片宽度完美兼容版

    判断input file图片宽度、大小最好的方法是用后端提交后来判断,但对应不会程序的朋友怎么办,门槛有点高。之前有分享过一次利用JS来判断input file图片宽度教程,但有个BUG,当第一次触发change方法判断true时,第二次input file随意选择一个都不会再次触发...

    js教程 153 4年前
最新更新