>>> import this

Unique window properties

May 11, 2020

Unique window properties

Filtering window properties to only unique local variables is actually incredibly simple. Just create an iframe and filter the current window’s properties by those properties. This is how I found the stList and areaList which I used to build a list of stations.

Source

// make sure it doesn't count my own properties
(function () {
    var results, currentWindow,
    // create an iframe and append to body to load a clean window object
    iframe = document.createElement('iframe');
    iframe.style.display = 'none';
    document.body.appendChild(iframe);
    // get the current list of properties on window
    currentWindow = Object.getOwnPropertyNames(window);
    // filter the list against the properties that exist in the clean window
    results = currentWindow.filter(function(prop) {
        return !iframe.contentWindow.hasOwnProperty(prop);
    });
    // log an array of properties that are different
    console.log(results);
    document.body.removeChild(iframe);
}());

Josh Manning

Written by Josh Manning who lives and works in Manhattan, KS.