How would I enumerate all the scripts available to a web page?

A

Angus

Hello

I have a web page which uses a js file on the server. I cannot see all the
javascript functions available to me in the html. I would like to have a
function which could print eg to a DIV section, all the available functions.
Just the function names is fine.

Is there any way to do this in javascript?

Angus
 
E

Evertjan.

Angus wrote on 15 apr 2007 in comp.lang.javascript:
I have a web page which uses a js file on the server. I cannot see
all the javascript functions available to me in the html. I would
like to have a function which could print eg to a DIV section, all the
available functions. Just the function names is fine.

Why not download the js.file and read it in notepad?
 
A

Angus

Yes I realise I can do that. I am trying to automate some web pages and
need to be able to enumerate javascript functions available programmatically
(well via javascript).

Is there some sort of script collection? Or some way of enumerating the
javascript objects programmatically?
 
S

scripts.contact

Hello

I have a web page which uses a js file on the server. I cannot see all the
javascript functions available to me in the html. I would like to have a
function which could print eg to a DIV section, all the available functions.
Just the function names is fine.

Is there any way to do this in javascript?


TRY this:

function FuncList(DIV){
for(var funcs in window)
if(typeof(window[funcs])=="function"){
var tnode=document.createTextNode(funcs)
DIV.appendChild(tnode)
}
}

the above will print all the global functions.
 
A

Angus

I have a web page which uses a js file on the server. I cannot see all the
javascript functions available to me in the html. I would like to have a
function which could print eg to a DIV section, all the available functions.
Just the function names is fine.
Is there any way to do this in javascript?

TRY this:

function FuncList(DIV){
for(var funcs in window)
if(typeof(window[funcs])=="function"){
var tnode=document.createTextNode(funcs)
DIV.appendChild(tnode)
}

}

the above will print all the global functions.

I tried this:

for(var funcs in window)
{
var fnode=document.getElementById(DIV);
fnode.appendChild(document.createTextNode(funcs + ' '));
}
}

Output was:
onbeforeunload onafterprint top location parent
offscreenBuffering frameElement onerror screen event
clipboardData onresize defaultStatus onblur window onload
onscroll screenTop onfocus Option length onbeforeprint frames
self clientInformation external screenLeft opener onunload
document closed history Image navigator status onhelp name

But none of my javascript functions. I tried also for (var funcs in
document) but didn't give me what I wanted.

I need the list of javascript function names.
 
E

Evertjan.

Angus wrote on 16 apr 2007 in comp.lang.javascript:
I tried this:
[..]

No that this helps you find userfunctions,
but perhaps someone can explain
this difference between window and document,
where appending with (document.f + ' ') gives undefined(!!!) [IE7]:

===========================
<div id=d><br></div>
<hr>
<div id=e><br></div>

<script type='text/javascript'>

function testttttttttttttttttt(){ alert(0); };

var d=document.getElementById('d');
for(var f in window)
d.appendChild(document.createTextNode(window.f + ' '));

var e=document.getElementById('e');
for(var f in document)
e.appendChild(document.createTextNode(window.f + ' '));

</script>
===========================

onbeforeunload onafterprint top location parent offscreenBuffering
frameElement onerror screen event clipboardData onresize defaultStatus
onblur window onload onscroll screenTop onfocus Option length
onbeforeprint frames self clientInformation XMLHttpRequest external
screenLeft opener onunload document closed history Image navigator status
onhelp name

-----------------------------------------------------

namespaces lastModified parentNode nodeType fileCreatedDate
onbeforeeditfocus bgColor oncontextmenu onrowexit embeds scripts
onactivate mimeType alinkColor onmousemove onselectstart oncontrolselect
body protocol onkeypress onrowenter onmousedown vlinkColor URL
onreadystatechange doctype onbeforedeactivate applets fileModifiedDate
onmouseover dir media defaultCharset firstChild plugins onafterupdate
ondragstart oncellchange cookie documentElement nextSibling nameProp
referrer ondatasetcomplete onmousewheel onerrorupdate onselectionchange
lastChild ondblclick onkeyup location forms title onrowsinserted
previousSibling compatMode onmouseup onkeydown onrowsdelete onfocusout
fgColor ondatasetchanged onmouseout parentWindow nodeName
onpropertychange onstop onhelp linkColor onbeforeactivate images
readyState frames all onbeforeupdate onclick childNodes onfocusin anchors
selection fileUpdatedDate domain security fileSize ownerDocument
ondataavailable styleSheets nodeValue attributes activeElement
implementation links URLUnencoded ondeactivate
 
A

Angus

Angus wrote on 16 apr 2007 in comp.lang.javascript:
I tried this:

[..]

No that this helps you find userfunctions,
but perhaps someone can explain
this difference between window and document,
where appending with (document.f + ' ') gives undefined(!!!) [IE7]:

===========================
<div id=d><br></div>
<hr>
<div id=e><br></div>

<script type='text/javascript'>

function testttttttttttttttttt(){ alert(0); };

var d=document.getElementById('d');
for(var f in window)
d.appendChild(document.createTextNode(window.f + ' '));

var e=document.getElementById('e');
for(var f in document)
e.appendChild(document.createTextNode(window.f + ' '));

</script>
===========================

onbeforeunload onafterprint top location parent offscreenBuffering
frameElement onerror screen event clipboardData onresize defaultStatus
onblur window onload onscroll screenTop onfocus Option length
onbeforeprint frames self clientInformation XMLHttpRequest external
screenLeft opener onunload document closed history Image navigator status
onhelp name

-----------------------------------------------------

namespaces lastModified parentNode nodeType fileCreatedDate
onbeforeeditfocus bgColor oncontextmenu onrowexit embeds scripts
onactivate mimeType alinkColor onmousemove onselectstart oncontrolselect
body protocol onkeypress onrowenter onmousedown vlinkColor URL
onreadystatechange doctype onbeforedeactivate applets fileModifiedDate
onmouseover dir media defaultCharset firstChild plugins onafterupdate
ondragstart oncellchange cookie documentElement nextSibling nameProp
referrer ondatasetcomplete onmousewheel onerrorupdate onselectionchange
lastChild ondblclick onkeyup location forms title onrowsinserted
previousSibling compatMode onmouseup onkeydown onrowsdelete onfocusout
fgColor ondatasetchanged onmouseout parentWindow nodeName
onpropertychange onstop onhelp linkColor onbeforeactivate images
readyState frames all onbeforeupdate onclick childNodes onfocusin anchors
selection fileUpdatedDate domain security fileSize ownerDocument
ondataavailable styleSheets nodeValue attributes activeElement
implementation links URLUnencoded ondeactivate

Yes, why no testttttttttttttttttt() in the list?
 
M

Marc

Yes, why no testttttttttttttttttt() in the list?

It does work in Firefox, so perhaps IE just doesn't add the user functions
to the same [window] object we expect...

btw, havn't got IE7 handy right now but have you tried:

d.appendChild(document.createTextNode(window.f + '\u00A0'));
 
M

Marc

Marc said:
Yes, why no testttttttttttttttttt() in the list?

It does work in Firefox, so perhaps IE just doesn't add the user functions
to the same [window] object we expect...

btw, havn't got IE7 handy right now but have you tried:

d.appendChild(document.createTextNode(window.f + '\u00A0'));


It gets stranger and stranger... check the differences between FF and IE



<div id=d><br></div>
<hr>
<div id=e><br></div>
<script type='text/javascript'>

function testttttttttttttttttt(){ alert(0); };

var d=document.getElementById('d');
for(var f in window)
d.appendChild(document.createTextNode(window.f + ' '));

var e=document.getElementById('e');
for(var f in document)
e.appendChild(document.createTextNode(window.f + ' '));
// the window object exposes the document enumerations?
</script>
 
E

Evertjan.

Marc wrote on 16 apr 2007 in comp.lang.javascript:
It gets stranger and stranger... check the differences between FF and IE

This works in IE7,
[FF does not recognize document.scripts]
and is the best I can do for the OP:

=======================================================
<div id=e><br></div>

<script type='text/javascript' id=firstScript>
function testttttttttttttttttt(){ alert(0); };
function brrrrrrrrrrrrr(){ alert(0); };

</script>
<script type='text/javascript'>

var z = ''
for(var f=0;f<document.scripts.length;f++ ){
z += '\n==========================\n'
+ document.scripts[f].innerHTML
}
document.getElementById('e').innerText = z

</script>
========================================================
 
A

Angus

Marc wrote on 16 apr 2007 in comp.lang.javascript:
It gets stranger and stranger... check the differences between FF and IE

This works in IE7,
[FF does not recognize document.scripts]
and is the best I can do for the OP:

=======================================================
<div id=e><br></div>

<script type='text/javascript' id=firstScript>
function testttttttttttttttttt(){ alert(0); };
function brrrrrrrrrrrrr(){ alert(0); };

</script>
<script type='text/javascript'>

var z = ''
for(var f=0;f<document.scripts.length;f++ ){
z += '\n==========================\n'
+ document.scripts[f].innerHTML}

document.getElementById('e').innerText = z

</script>
========================================================

That is good. I must say.... But.

It doesn't display the function defined in a .js file on the server.
Or at least in my IE6 it doesn't.

I would like to be able to view ALL the javascript functions.

There is a product called debugbar - www.debugbar.com which can
achieve this. It is an Internet Explorer BHO. Not sure how they do
it but they can. So there must be a way.

Angus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top