Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript(无jQuery)-谷歌浏览器有时会错误地检测窗口宽度_Javascript_Google Chrome_Browser_Width_Detect - Fatal编程技术网

Javascript(无jQuery)-谷歌浏览器有时会错误地检测窗口宽度

Javascript(无jQuery)-谷歌浏览器有时会错误地检测窗口宽度,javascript,google-chrome,browser,width,detect,Javascript,Google Chrome,Browser,Width,Detect,注意:这将作为一个bug报告给谷歌,但修复经常会被延迟 一个基于窗口宽度调用函数的网页在IE、Firefox等浏览器中工作,但在Chrome浏览器中“有时”会失败。该问题(在基于Chromium的浏览器中)仅在目标网页在浏览器启动时自动重新加载时发生 <script> var dde = document.documentElement; if(!document.documentElement) dde = document.body; // fix for IE6 and e

注意:这将作为一个bug报告给谷歌,但修复经常会被延迟

一个基于窗口宽度调用函数的网页在IE、Firefox等浏览器中工作,但在Chrome浏览器中“有时”会失败。该问题(在基于Chromium的浏览器中)仅在目标网页在浏览器启动时自动重新加载时发生

<script>

var dde = document.documentElement;

if(!document.documentElement) dde = document.body; // fix for IE6 and earlier 

myWidth = Math.max(dde.scrollWidth,dde.offsetWidth,dde.clientWidth);

if(myWidth < 960) document.location.href="http://www.gooplusplus.com/mini.php";  

</script>

var dde=document.documentElement;
如果(!document.documentElement)dde=document.body;//修复IE6和更早版本
myWidth=Math.max(dde.scrollWidth、dde.offsetWidth、dde.clientWidth);
if(myWidth<960)document.location.href=”http://www.gooplusplus.com/mini.php";  

进一步的测试发现,在浏览器启动时,Chrome从非最大化的窗口大小中获取窗口宽度结果,即使窗口实际上是最大化的。此外,此错误仅发生在非活动浏览器选项卡上

在找到解决方案的过程中,需要两个步骤来检测:

(1) 浏览器是否基于Chromium?-->
navigator.userAgent.indexOf(“Chrome/”)>0

(2) 选项卡是否处于非活动状态?--><代码>document.webkitVisibilityState==“隐藏”

测试URL:

我的部分解决方案:

<script>

var dde = document.documentElement;

var tabVisible = document.webkitVisibilityState;

if(!document.documentElement) dde = document.body; // fix for IE6 and earlier 

myWidth = Math.max(dde.scrollWidth,dde.offsetWidth,dde.clientWidth);

if( ( navigator.userAgent.indexOf("Chrome/")<0 || tabVisible!="hidden" ) && myWidth < 960 ) 
    document.location.href="http://www.gooplusplus.com/mini.php";  

</script>

var dde=document.documentElement;
var tabVisible=document.webkitVisibilityState;
如果(!document.documentElement)dde=document.body;//修复IE6和更早版本
myWidth=Math.max(dde.scrollWidth、dde.offsetWidth、dde.clientWidth);
if((navigator.userAgent.indexOf(“Chrome/”)