List all properties of window object?

后端 未结 3 892
慢半拍i
慢半拍i 2021-01-04 19:19

I\'m looking to (dynamically) obtain a list of HTML elements the browser is currently aware of, such as HTMLPreElement, HTMLSpanElement etc. These

相关标签:
3条回答
  • 2021-01-04 19:55
    for (var prop in window)
        console.log(prop);
    

    That's what you need?

    0 讨论(0)
  • 2021-01-04 20:02

    In Firefox, it seems to be the behavior of elements that their global object is not added unless explicitly requested as a global variable or property. Perhaps Firefox lazy loads them into the environment so that they don't consume memory unless they're actually needed.

    It seems that they do not show up when simply requesting the keys of the global object via Object.getOwnPropertyNames unless they've first been explicitly referenced as described above.

    http://jsfiddle.net/mBAHm/

    0 讨论(0)
  • 2021-01-04 20:07
    var obj = window;
    while(obj){
        for(let prop of Reflect.ownKeys(obj)){
            console.log(prop);
        };
        obj = Object.getPrototypeOf(obj);
    };
    
    0 讨论(0)
提交回复
热议问题