473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Locating all event handlers and scripts in a document

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 <scriptelement or in the event
handlers of other elements. Are there other legal locations?

Finding the <scripttags 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

Aug 10 '06 #1
2 1191
niks wrote:
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 <scriptelement 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 <scripttags 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.
Aug 10 '06 #2
Richard Cornford said the following on 8/10/2006 8:04 PM:
niks wrote:
>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?
That is not always true. I would wager it's false more than it's true.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
6
by: Tim Fooy | last post by:
Hi all, I have the following problem. In my page i have a large <div> with tags inside it that have event handlers on them (onclick etc.). When i run div.innerHTML = moreText + div.innerHTML,...
2
by: Pavils Jurjans | last post by:
Hello, I wanted to propose a small class that would help to overcome the feature that's missing in MSIE. I'd like to get some feedback from people and, perhaps, improvements in code/other ideas:...
1
by: glevik | last post by:
Hello, I have written a script that gets trigered by IE's toolbar button. In this script I would like to asign an event handler to an element of the document currently open in IE. The way one...
0
by: Vasiliy | last post by:
Hi all! I'm developing an application to manage word templates and documents. Documents are stored in database, so when user wants to edit a document i make a local copy of this document and then...
5
by: jaysonnward | last post by:
Hello All: I've recently been recreating some 'dropdown menus' for a website I manage. I'm writing all my event handlers into my .js file. I've got the coding to work in Firefox, but the...
2
by: Safalra | last post by:
Recently I've rewritten much of my old Javascript code to use DOM functions so that enhancements can be attached to documents without needing to alter the HTML code. I assumed that adding event...
4
by: eggie5 | last post by:
I have this even handler (using prototype.js): showCommentsLinks.observe('click', function(event) { alert('hi') }); It's attaching to a link element: <a id="showCommentsLink"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.