列出站点使用的所有js全局变量(并非全部定义!) [英] List all js global variables used by site (not all defined!)
问题描述
列出网站使用的所有全局变量的方法是什么?任何浏览器javascript调试器都可以这样做吗?使用我的意思是READ,没有改变/添加。检测iframe,也会很好。
What is the way to list all global variables that have been used by the site? Can any browser javascript debugger do that? By used I mean READ, not changed/added. Detect iframe ones, would be nice too.
请注意:
我需要获取一个由网站触及的全局变量列表。并非所有这些或已添加的或已编辑的,在网站脚本中的任何位置使用的那些。
PLEASE NOTE: I need to get a list of global variables "touched" by site. Not all of them or added ones or edited ones, the ones that were used anywhere in the site scripts.
推荐答案
在Chrome中,转到Dev工具并打开控制台。
然后键入以下内容:
In Chrome, go to Dev tools and open the console. Then type in the following:
Object.keys( window );
这将为您提供一个包含所有全局变量的数组。
This will give you an Array of all the global variables.
编辑
在Google上搜索了一下后,我找到了办法。你需要 firefox 和 jslinter 插件。
After searching on Google a bit, I found a way. You will need firefox and the jslinter addon.
设置完成后,打开jslinter并转到左栏上的选项 - >检查所有内容,但容忍未使用的参数。
Once setup, open jslinter and go to Options->check everything on the left column except "tolerate unused parameters".
然后在网页上运行jslinter并向下滚动结果。您将获得未使用变量的列表(全局,然后是每个函数的本地变量)。
Then run jslinter on the webpage and scroll down in the results. You will have a list of unused variables (global and then local to each function).
现在运行对象。控制台中的键(窗口);
并比较两者的结果以确定使用哪些。
Now run Object.keys(window);
in the console and compare the results from both to figure out which ones are used.
这篇关于列出站点使用的所有js全局变量(并非全部定义!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!