Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Oakland, CA
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    capturing JS functions in IE [please reply]

    [ Same message, with a plea for others to respond, even if it is to confirm whether this is possible or not. ]

    Hello all,

    I'm trying to catalog all the functions declared in a page, for
    debugging purposes, but I can't seems to access code from external libraries in
    IE.

    I have successfully captured inline functions, by searching the "text"
    property of each element of the "document.scripts" array. In NS/Moz, thankfully, you can access any global entity (like a function) in the "top" object, inline or external. (Does anyone know how this works with Safari/Omni clients?)

    Back to my problem:
    In IE, as I understand it, external libraries don't have a text property to search
    - it seems that the "text" property basically refers to the code between the actual SCRIPT tags and NOT the code inserted by an external file.

    I'm keeping my hopes up, that code from an externally loaded file is in an accessible area of IE's DOM - perhaps in one of their infamous collections?... Any ideas?

    Below is a rudimentary example of how I've successfully captured
    function declarations in IE and NS/Moz.

    /snip------------

    // browser flag
    isIE = (navigator.appName.toString().indexOf('Micro') != -1) ? 1 : 0;
    // alias document object
    DC = document;
    // if client is IE compatible...
    if (isIE) {
    // alias document.scripts array
    var s = DC.scripts;
    // loop through and catalog functions per script
    for (var i = 0; i < s.length; i++) {
    // initial search index
    var x = 0;
    // until the entire script text has been searched
    while (s[i].text.indexOf('function ',x) != -1) {
    // capture next starting index
    x = s[i].text.indexOf('function ',x) + 9;
    // write next declared function
    DC.write('<P>',s[i].text.substring(x,s[i].text.indexOf('(',x)),'<\/P>');
    }
    }
    } else { // otherwise if client is netscape compatiblae
    // loop through and display top-level entities
    for (var i in self) {
    // if this is a function, write name to page
    if (typeof(self[i]) == 'function') DC.write('<P>',i,'<\/P>');
    }
    }

    ------------snip/

    Like I said before, I can't test this on Safari or Omni... Would someone let me know how this script performs with these clients?

    - Thanks much!
    Last edited by rawsweets; 08-04-2003 at 09:21 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You got a demo page?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    Oakland, CA
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Demo page available

    Originally posted by brothercake
    You got a demo page?
    Here's a demonstration of the function capturing script, on geocities.
    Hope it helps you - help me, that is! :-)

    -> http://www.geocities.com/rawsweets/index.htm

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesn't work in any browser I tried, not even mozilla ...?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #5
    New Coder
    Join Date
    Aug 2002
    Location
    Oakland, CA
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Please confirm your results...

    Originally posted by brothercake
    It doesn't work in any browser I tried, not even mozilla ...?
    Works on N6+,Mo,IE5+ Mac & PC... I can't explain your errors, because the above mentioned browser work fine on my systems. Can anyone else corroborate these results?

    What you should see is the text "someFunc" and "anotherFunc" under the horizontal rule; these are the two custom functions which are declated in the first SCRIPT tag. You may see other stuff below it (depending on the browser), but the capturing routine will write to the page, the name of the custom functions first.

    Let me know if anyone else encounters the same result.

    - rawsweets

  • #6
    New Coder
    Join Date
    Nov 2002
    Location
    London, UK
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got the desired (someFunc,anotherFunc) output in IE6 with a syntax error reported on line 2.

    On Mozilla i got the same output plus a lot more. I also got some errors though :-

    uncaught exception permission denied to property window.fullScreen.
    document.y|o has no properties
    syntax error

    Hope that helps

    Adam

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh sorry - I didn't realise that output was the script working

    Here's what Safari produces:
    Code:
    EvalError
    RangeError
    ReferenceError
    SyntaxError
    TypeError
    URIError
    someFunction
    anotherFunction
    close
    alert
    setTimeout
    getSelection
    clearInterval
    scroll
    scrollBy
    resizeBy
    addEventListener
    prompt
    resizeTo
    open
    scrollTo
    moveBy
    moveTo
    confirm
    clearTimeout
    focus
    blur
    setInterval
    captureEvents
    releaseEvents
    removeEventListener
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    New Coder
    Join Date
    Aug 2002
    Location
    Oakland, CA
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    The demonstration is not the goal

    Originally posted by Adam20002
    I got the desired (someFunc,anotherFunc) output in IE6 with a syntax error reported on line 2.

    On Mozilla i got the same output plus a lot more. I also got some errors though :-

    uncaught exception permission denied to property window.fullScreen.
    document.y|o has no properties
    syntax error

    Hope that helps

    Adam
    This helps somewhat, however this thread is going off topic with the demonstration issue. I'm trying to see how to make this work with external libraries, not inline code.

    BTW: The error in IE is because of the geocities code, not mine. (I have Microsoft Script Debugger installed, and it said the error occurred when one of their functions were called.) Also, the Moz error is negligible and can be refined further.

    My issue is how to make this work on IE with external libraries. Consider the demonstration link as a possible way of doing this, since it works with inline code (albiet with errors).

    Frankly, I don't think JS can do it on IE, and I'll have to look into VBscript options in order to search an external library or access declared functions. I've been searching a long time with no results.

    - rawsweets

  • #9
    New Coder
    Join Date
    Aug 2002
    Location
    Oakland, CA
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thanks for the Safari output!

    Originally posted by brothercake
    Oh sorry - I didn't realise that output was the script working

    Here's what Safari produces:
    Code:
    ...
    someFunction
    anotherFunction
    ...
    It is becoming more and more important that this routine is compatible with Safari. Thanks for much for this output report. Based on the output, I'm pretty sure that Safari took the NS compatible method of scanning the "top/self" object. Thus functions declared anywhere (inline or external) would be available to inspect.

    Thanks again!!

    .. Anyone know a good place to get VBscript advice? I'm ready (desperate) to find a way to scan externally loaded functions in IE.

    - rawsweets


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •