Hmm... That's interesting. In all browsers below code will give you
alert with 123:
javascript:var xxx = 123;alert(window.xxx)
But output of below function is browser's engine dependant:
var xxx = 123
function test()
{
var out = document.getElementsByTagName('textarea')[0]
for (var obj in window)
{
if (typeof(window[obj])!='function')
out.value+='\nwindow.'+obj +' => ('+typeof(window[obj])+')
'+ window[obj];
}
}
In FF it will show you quite a lot of stuff and your global variables.
In Chrome you will get even more as some "null" variables will be shown
(like window.on*).
In IE you will get pretty much the same as in Chrome, but without global
variables.
And in Opera... Well I was kinda shocked, because the output was
"window.opera => (object) [object Opera]" :-)). Then I noticed some of
stuff linked to window object in Opera doesn't have toString methods so
you'll have use something like:
{out.value+='\nwindow.'+obj +' => ('+typeof(window[obj])+') '+
window[obj];}catch (e){}
And then it will work in Opera too and it will show you global vars.
And as you said before setting window.xxx rather then var xxx will make
it work for IE too. Still watching the variable xxx in IE's dev tool
_is_ possible in both situations. The only drawback is that you won't
see your watch if you're not debugging (simply switching to debugging
won't work - you'll have to break on some point).
Regards,
Nux.