firebug - Get all javascript variables in document - Stack Overflow

admin2025-04-10  0

Is there a way to retrieve all Javascript 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.

Is there a way to retrieve all Javascript 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.

Share Improve this question asked Nov 10, 2010 at 16:13 Tim FerrellTim Ferrell 1,3663 gold badges18 silver badges41 bronze badges 3
  • 2 Can you describe what it is you want to acplish by doing this? As it stands, the question is pretty vague. There can be lots of "variables" in lots of different places "within" a page, and some of them can be discovered while others really can't. – Pointy Commented Nov 10, 2010 at 16:20
  • Let me elaborate- I'm developing an application that lives within a web page. For a session restore style function, I'd like to pull all of the variables out of the page on an interval, and store that for restoration later. I feel the better solution, for now, would be to pull out certain variables that are necessary to create a a session, but it would still be an interesting exercise to iterate through the global variables. – Tim Ferrell Commented Nov 19, 2010 at 15:50
  • This looks like a duplicate question: stackoverflow./questions/2762075/… – Anderson Green Commented Jan 12, 2013 at 19:56
Add a ment  | 

2 Answers 2

Reset to default 4

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./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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744284919a239667.html

最新回复(0)