开发者

Get all javascript variables in document

Is there a way to retrieve all Javascrip开发者_如何学Ct variables within a page?

For example, Firebug can view all of the JS vars, so I know it's possible, but I'm unsure on how to do it.


To get global variables:

var x=[];
for (var i in window){
    x.push(i)
};
alert(x.join("\\"));

They are stored in window object

you can see more info here:

http://seanmonstar.com/post/708979238/iterating-global-variables-in-internet-explorer


Any unscoped varilables generally end up getting attached to the global window object, so you could try looping over it to see what variables (and properties) have been attached, though be warned there is a lot of stuff already attached to it.

Any scoped variables will of course be in their own scope - which is a clearly a bit more problematic to retrieve in a reliable way. Firebug is able to work it's magic in part because it is an extension and able to operate outside the edges of typical browser security, allowing more interesting and deep introspection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜