0

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?

AstroCB
  • 12,337
  • 20
  • 57
  • 73
Moshe
  • 57,511
  • 78
  • 272
  • 425
  • Are you talking about javascript injection to gain the value of a specific input, or listing out all inputs on the page? – Jay Dec 11 '09 at 05:09
  • Well, once I see all of the values, I can prbably just use a *javascript: var = val*, right? I'm asking how to list all of the variables by name so I can change the necessary ones. – Moshe Dec 11 '09 at 05:13

2 Answers2

4

Try this view-variables bookmarklet.

Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110
1

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>
AmbrosiaDevelopments
  • 2,576
  • 21
  • 28