Locating all event handlers and scripts in a document

N

niks

Is there a standard way of traversing the DOM to find all the
javascript in a document? As far as I know, the only legal positions
for javascript in the DOM is within a <script> element or in the event
handlers of other elements. Are there other legal locations?

Finding the <script> tags is easy enough using
document.getElementsByTagName. But locating all event handlers by
traversing the tree of elements and querying for all attributes such as
onclick, onmouseover etc. feel pretty heavy. Is there some simpler way
of doing this?

Thanks in advance,
Nik
 
R

Richard Cornford

niks said:
Is there a standard way of traversing the DOM to find
all the javascript in a document?

Why would there be, as the script got into the document because someone
chose to put it there, and so should know where it is?
As far as I know, the only legal positions for javascript
in the DOM is within a <script> element or in the event
handlers of other elements. Are there other legal locations?

That would depend on how 'legal' you regarded putting javascript
pseudo-protocol "URLs" into HREF, SRC, ACTION, etc, attributes.
Finding the <script> tags is easy enough using
document.getElementsByTagName. But locating all event
handlers by traversing the tree of elements and querying
for all attributes such as onclick, onmouseover etc. feel
pretty heavy.

And is not going to find listeners attached with - addEventListener - in
W3C standard browsers or - attachEvent - in IE.
Is there some simpler way of doing this?

Probably not, which does not mean there is no solution to whatever the
real problem is.

Richard.
 
R

Randy Webb

Richard Cornford said the following on 8/10/2006 8:04 PM:
Why would there be, as the script got into the document because someone
chose to put it there, and so should know where it is?

That is not always true. I would wager it's false more than it's true.
 

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

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top