<i id='glP2O'><tr id='glP2O'><dt id='glP2O'><q id='glP2O'><span id='glP2O'><b id='glP2O'><form id='glP2O'><ins id='glP2O'></ins><ul id='glP2O'></ul><sub id='glP2O'></sub></form><legend id='glP2O'></legend><bdo id='glP2O'><pre id='glP2O'><center id='glP2O'></center></pre></bdo></b><th id='glP2O'></th></span></q></dt></tr></i><div id='glP2O'><tfoot id='glP2O'></tfoot><dl id='glP2O'><fieldset id='glP2O'></fieldset></dl></div>

        <small id='glP2O'></small><noframes id='glP2O'>

      1. <legend id='glP2O'><style id='glP2O'><dir id='glP2O'><q id='glP2O'></q></dir></style></legend>
        <tfoot id='glP2O'></tfoot>
          <bdo id='glP2O'></bdo><ul id='glP2O'></ul>

        为什么在 Chrome 的某些网站上 console.log 是一个空

        时间:2023-09-04
        <tfoot id='8ff4v'></tfoot>

            <tbody id='8ff4v'></tbody>
        1. <i id='8ff4v'><tr id='8ff4v'><dt id='8ff4v'><q id='8ff4v'><span id='8ff4v'><b id='8ff4v'><form id='8ff4v'><ins id='8ff4v'></ins><ul id='8ff4v'></ul><sub id='8ff4v'></sub></form><legend id='8ff4v'></legend><bdo id='8ff4v'><pre id='8ff4v'><center id='8ff4v'></center></pre></bdo></b><th id='8ff4v'></th></span></q></dt></tr></i><div id='8ff4v'><tfoot id='8ff4v'></tfoot><dl id='8ff4v'><fieldset id='8ff4v'></fieldset></dl></div>
            • <bdo id='8ff4v'></bdo><ul id='8ff4v'></ul>
              <legend id='8ff4v'><style id='8ff4v'><dir id='8ff4v'><q id='8ff4v'></q></dir></style></legend>

              • <small id='8ff4v'></small><noframes id='8ff4v'>

                1. 本文介绍了为什么在 Chrome 的某些网站上 console.log 是一个空函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  转到 Twitter 的登录页面并在控制台中输入以下内容:

                  Go to Twitter's login page and type the following in the console:

                  window.addEventListener('keypress', function(e){console.log('hello')}, true)
                  

                  (注意:如何将第三个参数设置为 true 以启用事件捕获.这会导致事件在被子元素消费之前首先被窗口拦截.)

                  (NOTE: how the third parameter is set to true which enables event capture. This causes events to be intercepted first by the window before being consumed by a child element.)

                  尝试按一些键.注意 hello 是如何不输出到控制台的.为 keydownkeyup 添加事件监听器不会改变任何东西.

                  Try pressing some keys. Notice how hello isn't output to the console. Adding an event listener for keydown or keyup doesn't change anything.

                  hello 将在大多数网站上获得输出,但不会在 Twitter 或 Gmail 等网站上获得输出.

                  hello will get output on most websites, but not on sites like Twitter or Gmail.

                  为什么?是什么阻止了事件侦听器?

                  Why? What's stopping the event listener?

                  似乎在 Firefox 上按预期工作.但不是铬.为什么 Chrome 没有按预期触发事件侦听器?

                  Seems to work as expected on Firefox. But not Chrome. Why isn't Chrome firing the event listener as expected?

                  编辑 2:正如下面的一些人所推断的,console.log 是 Chrome 上的一个空函数,用于 Twitter 和 Gmail 等网站.这是为什么呢?

                  EDIT 2: As deduced by a few people below, console.log is an empty function on Chrome for sites like Twitter and Gmail. Why is that?

                  推荐答案

                  因为那些网站已经专门设置了(显然是针对webkit):

                  Because those sites have specifically set (for webkit apparently):

                  console.log = function(){};
                  

                  但是,在 Chrome 中,您可以通过在控制台中发出以下命令来恢复原始 log() 功能:

                  However, in Chrome you can restore the original log() functionality by issuing this command in console:

                  console.log = console.__proto__.log
                  

                  那么你可以这样做:

                  window.addEventListener('keypress', function(e){console.log('hello')}, true)
                  

                  它应该按预期工作.

                  这篇关于为什么在 Chrome 的某些网站上 console.log 是一个空函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:谷歌地图的双击事件传播 下一篇:使用纯 JavaScript 获取事件的选择元素值

                  相关文章

                  最新文章

                  1. <small id='fPtJH'></small><noframes id='fPtJH'>

                  2. <tfoot id='fPtJH'></tfoot>
                    <legend id='fPtJH'><style id='fPtJH'><dir id='fPtJH'><q id='fPtJH'></q></dir></style></legend>
                        <bdo id='fPtJH'></bdo><ul id='fPtJH'></ul>
                    1. <i id='fPtJH'><tr id='fPtJH'><dt id='fPtJH'><q id='fPtJH'><span id='fPtJH'><b id='fPtJH'><form id='fPtJH'><ins id='fPtJH'></ins><ul id='fPtJH'></ul><sub id='fPtJH'></sub></form><legend id='fPtJH'></legend><bdo id='fPtJH'><pre id='fPtJH'><center id='fPtJH'></center></pre></bdo></b><th id='fPtJH'></th></span></q></dt></tr></i><div id='fPtJH'><tfoot id='fPtJH'></tfoot><dl id='fPtJH'><fieldset id='fPtJH'></fieldset></dl></div>