View list of all JavaScript variables in Google Chrome Console

后端 未结 15 2113
星月不相逢
星月不相逢 2020-11-29 14:32

In Firebug, the DOM tab shows a list of all your public variables and objects. In Chrome\'s console you have to type the name of the public variable or object you want to ex

相关标签:
15条回答
  • 2020-11-29 15:18

    To view any variable in chrome, go to "Sources", and then "Watch" and add it. If you add the "window" variable here then you can expand it and explore.

    0 讨论(0)
  • 2020-11-29 15:19

    Updated method from same article Avindra mentioned — injects iframe and compare its contentWindow properties to global window properties.

    (function() {
      var iframe = document.createElement('iframe');
      iframe.onload = function() {
        var iframeKeys = Object.keys(iframe.contentWindow);
        Object.keys(window).forEach(function(key) {
          if(!(iframeKeys.indexOf(key) > -1)) {
            console.log(key);
          }
        });
      };
      iframe.src = 'about:blank';
      document.body.appendChild(iframe);
    })();

    0 讨论(0)
  • 2020-11-29 15:20

    Type: this in the console,

    to get the window object I think(?), I think it's basically the same as typing window in the console.

    It works at least in Firefox & chrome.

    0 讨论(0)
提交回复
热议问题