Firefox 浏览器 document.write 之后...

1402次阅读  |  发布于5年以前

今天遇到一个诡异问题,经查问题出现在 Firefox 浏览器上 document.write 之后,我把复现问题的主要代码摘出来了:

<!DOCTYPE html>  
<html>  
  <head>  
    <meta charset="utf-8">  
  </head>  
  <script>  
    // navigator.a = 1;  
    setTimeout( function(){  
      document.write( "blank" );  
      alert( "window: " + ( window.window === window ) );  
      alert( "navigator: " + ( window.navigator === navigator ) );  
      alert( "document: " + ( window.document === document ) );  
      alert( "location: " + ( window.location === location ) );  
      alert( "String: " + ( window.String === String ) );  
    }, 1 );  
  </script>  
</html>  

如果不运行代码,凭经验你们先猜猜以上 alert 都会是什么结果?(限 Firefox 浏览器)

戳这里在线试试

打开 // navigator.a = 1; 这个注释后,再重新运行一下试试。

最后,我也没弄明白为什么。

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8