views:

318

answers:

2

Hi, I've seen javascript (and written some too) to show the contents of input tags (useful if the guy before you left a password in an input...), but I want to use JS to show the Javascript variables that exist in the page.

The reason I want to do this is because I want to check out a file sharing site to see if it's real or just a rootkit hotbed.

Any ideas?

+3  A: 

Try this view-variables bookmarklet.

cxfx
Didn't work... (Chrome)
Moshe
Works in Firefox
Moshe
+1  A: 

There are DOM inspectors in both IE and FF. In older IE versions you'll want the Document Tree section of their Web Developer Accessories. In IE8 there go to Tools->Developer Tools and there you have a nice little console to play with that will show you these things. In FF you can use the built in DOM inspector or Firebug (my personal favourite). There is also this bookmarklet, here is the code (cleaned up):

<html>
    <head>
        <script type="text/javascript">
            var wer = "asdasd";

            function getEm()
            {
                var x,d,i,v,st;
                x=open();
                d=x.document;
                d.open();

                function hE(s)
                {
                    s=s.replace(/&/g,"&amp;");
                    s=s.replace(/>/g,"&gt;");
                    s=s.replace(/</g,"&lt;");
                    return s;
                }

                d.write("<style>td{vertical-align:top; white-space:pre; } table,td,th { border: 1px solid #ccc; } div.er { color:red }</style><table border=1><thead><tr><th>Variable</th><th>Type</th><th>Value as string</th></tr></thead>");

                for (i in window)
                {
                    if (!(i in x) )
                    {
                        v=window[i];
                        d.write("<tr><td>" + hE(i) + "</td><td>" + hE(typeof(window[i])) + "</td><td>");
                        if (v===null)
                            d.write("null");
                        else if (v===undefined)
                            d.write("undefined");
                        else
                            try
                            {
                                st=v.toString();
                                if (st.length)
                                    d.write(hE(v.toString()));
                                else
                                    d.write("%C2%A0")
                            }
                            catch(er)
                            {
                                d.write("<div class=er>"+hE(er.toString())+"</div>")
                            }

                        d.write("</pre></td></tr>");
                    }
                }

                d.write("</table>");
                d.close();
            }
        </script>
    </head>
    <body onload="getEm()">
    </body>
</html>
Ambrosia
Cleaned up source code FTW! thanks...
Moshe