#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    33
    Rep Power
    12

    Question finding all Javascript objects and functions in a page


    I know I've seen code that dumps (at least it seemed!) all the objects in a window and shows their properties--presumably using a for..in loop or nested for..in loops.

    But, alas, when I tried to do same myself, I don't seem to get far because I can't list them without knowing what they are first. (That is, I can list user-defined properties of Object or Array or whatever well enough, but I haven't figured out how to list automatically everything pertaining to classes deriving from Object and so on.) I'm not concerned about listing (or just assigning to a variable) DOM objects in a web page--I think I can handle that.

    But how do I retrieve a tree or similar object that contains all user-defined classes and functions? Obtaining the core or built-in classes and functions is also desirable. (I realize the function code won't appear, but it's nice to know what's there.)

    For example, in Venkman we can view loaded scripts and open windows. Selecting an open script permits dropping down a list of functions in that script, which in turn can highlight that function in a source code window.

    I want to be able to do something similar (or at least collect the names of the objects and functions). I tried examining some of the Javascript Venkman source, but quickly became lost.

    I feel like I once knew how to do this, but if I did, I can't remember it now that I need it. I'm a relative Javascript newbie.

    Can anybody help? Thanks in advance.
    Bill
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    33
    Rep Power
    12
    So no one knows a way--via the prototype object or whatever--the derive a tree or list of objects, classes, or functions on the page?
    Bill
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Manchester, UK
    Posts
    80
    Rep Power
    14
    i know that IE and opera will list properties with the following:
    function ShowProperties() {
    for (property in event) {
    alert(property);
    }
    }

    <span onclick="javascript:ShowProperties();">click me</span>
    i've not tried it with NN though.

    give it a bash. bear in mind that this example only does it for the event, you could do all sorts of things and it's unlikely to reveal anything but browser specific stuff which means it's not that portable.

    robert.
    Robert.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    33
    Rep Power
    12
    Thanks so much for your response. I've been away for a while, or I would have responded sooner. I'd been trying similar things, and your answer triggered me to come back to the problem.

    Seem to be making some progress this time around. Thanks again.

    Bill
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    147
    Rep Power
    12
    you mentioned not needing a DOM tree, but you might still be interested in this page.

IMN logo majestic logo threadwatch logo seochat tools logo