...

capturing JS functions in IE

rawsweets
08-01-2003, 10:30 PM
[ 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!

brothercake
08-09-2003, 08:41 AM
You got a demo page?

rawsweets
08-09-2003, 10:52 PM
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

brothercake
08-10-2003, 12:06 PM
It doesn't work in any browser I tried, not even mozilla ...?

rawsweets
08-10-2003, 05:18 PM
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

Adam20002
08-10-2003, 06:23 PM
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

brothercake
08-10-2003, 07:17 PM
Oh sorry - I didn't realise that output was the script working :o

Here's what Safari produces:

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

rawsweets
08-10-2003, 07:26 PM
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

rawsweets
08-11-2003, 06:37 AM
Originally posted by brothercake
Oh sorry - I didn't realise that output was the script working :o

Here's what Safari produces:

...
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum