2018-03-01

聚沙

获取自定义全局变量

https://davidwalsh.name/global-variables-javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
(function() {
    const iframe = document.createElement('iframe')
    iframe.onload = function() {
        const iframeKeys = Object.keys(iframe.contentWindow)
        const currentKesy = Object.keys(window)

        const results = currentKesy
            .filter(key => !iframeKeys.includes(key))

        console.log(results)
    }

    iframe.src = 'about:blank'
    document.body.appendChild(iframe)
})()

Comments