Javascript 是否有事件告诉您window.outerWidth何时成为准确值?

Javascript 是否有事件告诉您window.outerWidth何时成为准确值?,javascript,dom,javascript-events,chrome-for-android,Javascript,Dom,Javascript Events,Chrome For Android,在Android Chrome上,当打开一个新选项卡并导航到一个URL时,或者当放大一个页面然后导航到一个新URL时,window.outerWidth和偶尔(document.documentElement.clientWidth)的值并不总是准确的。在最多3秒钟后,它们获得准确的值。是否有来自窗口或DOM的相应事件,我可以监听以检测这一时刻,还是必须依赖循环 下面是问题的一个演示: 我只在Android Chrome上看到过,也许是个bug 下面是当行为出现时,我从该页面获得的输出。请注意,

在Android Chrome上,当打开一个新选项卡并导航到一个URL时,或者当放大一个页面然后导航到一个新URL时,window.outerWidth和偶尔(document.documentElement.clientWidth)的值并不总是准确的。在最多3秒钟后,它们获得准确的值。是否有来自窗口或DOM的相应事件,我可以监听以检测这一时刻,还是必须依赖循环

下面是问题的一个演示: 我只在Android Chrome上看到过,也许是个bug

下面是当行为出现时,我从该页面获得的输出。请注意,window.outerWidth(OW)在1100ms之前等于0:

body onload()
-0ms CW: 980 IW: 980 OW: 0
-100ms CW: 980 IW: 980 OW: 0
-200ms CW: 980 IW: 980 OW: 0
-300ms CW: 980 IW: 980 OW: 0
-400ms CW: 980 IW: 980 OW: 0
-500ms CW: 980 IW: 980 OW: 0
-600ms CW: 980 IW: 980 OW: 0
-700ms CW: 980 IW: 980 OW: 0
-800ms CW: 980 IW: 980 OW: 0
-900ms CW: 980 IW: 980 OW: 0
-1000ms CW: 980 IW: 980 OW: 0
-1100ms CW: 980 IW: 980 OW: 384
-1200ms CW: 980 IW: 980 OW: 384
-1300ms CW: 980 IW: 980 OW: 384
以下是测试页面的HTML:

<html>
<head>
<script>
  var count = 0;
  var interval = 100;
  function init(){
    log("body onload()");
    outputStats();
  }
  function outputStats() {
    log("-" + (count * interval) + "ms  CW: " + 
    document.documentElement.clientWidth+"  IW: "+window.innerWidth+"  OW: " +window.outerWidth);
    count++
    if(count < 50){
      setTimeout(outputStats, interval);
    }
  }
  function log(t){
    var logDiv = document.getElementById("content");
    var tDiv = document.createElement("div");
    tDiv.appendChild(document.createTextNode(t));
    logDiv.appendChild(tDiv);
  }
</script>
</head>
<body onload="init();" style="font-family:sans-serif;">
  <div id="content">
    Using Android Chrome: open this page in a new tab, or go to another web page then scale it up, and navigate to this page. The window.outerWidth does not show the correct value for up to a few seconds.<br/>
    <br/>
    CW: document.documentElement.clientWidth<br/>
    IW: window.innerWidth<br/>
    OW: window.outerWidth<br/>
    <br/>
  </div>
</body>
</html>

var计数=0;
var区间=100;
函数init(){
日志(“body onload()”;
outputStats();
}
函数outputStats(){
日志(“-”+(计数*间隔)+“毫秒连续波:”+
document.documentElement.clientWidth+“IW:”+window.innerWidth+“OW:”+window.outerWidth);
计数++
如果(计数<50){
setTimeout(outputStats,interval);
}
}
功能日志(t){
var logDiv=document.getElementById(“内容”);
var tDiv=document.createElement(“div”);
tDiv.appendChild(document.createTextNode(t));
日志分区附件(tDiv);
}
使用Android Chrome:在新选项卡中打开此页面,或转到另一个网页,然后将其放大,然后导航到此页面。window.outerWidth在几秒钟内没有显示正确的值。

CW:document.documentElement.clientWidth
IW:window.innerWidth
OW:window.outerWidth