473,699 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Finding the <scripttags is easy enough using
document.getEle mentsByTagName. 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 1211
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 <scriptelemen t 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.getEle mentsByTagName. 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 - addEventListene r - 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.javas cript 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
3592
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 language="JavaScript" type="text/javascript"> function show(that) { if (box.style.visibility=='hidden') { that.style.visibility = 'visible'}; }
6
2822
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, either before or after the page has fully loaded, all of those event handlers are dropped: the actions for the event are not executed anymore. I can't find anything related to this problem on the internet. Has anyone ever encountered a similar...
2
1799
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: /******************************************************************************************* DCListener class Description: provides basic event listener functionality Interface :
1
1456
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 access the document object from a toolbar button script is: var doc = external.menuArguments.document; Now assuming the document has an element called TextArea1, the logical
0
2171
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 open it through ms word. I have handlers for beforeClose, beforeSave and Quit events. The problem is following: i open any number of documents for editing, then edit any document (say, document A) and don't save it (by ctrl+s, save button e t.c.)...
5
4539
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 onmouseleave / onmouseout event I've attached to my hidden drop down (in this case an <ul>), is not firing correctly. It seems that when the mouse enters the ul it fires the mouseleave event. The problem is in the hideMenu2(e) function. I'm copying...
2
2107
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 handlers to document.body would have the same effect as adding those event handlers through attributes of the body element, but this turned out not to be the case for key events. Take this example page (IE-specific code removed): ...
4
2140
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" href="comments/">Show Comments</a>
0
8686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8911
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6533
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.