473,609 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

access 'event' in a handler from in-line registration

I have code which is created from a content mamagement system. It places
some handlers on tags with in-line registration:

<tag... onmousedown="mo usedownHandler( this);" ...>
I want to modified the handler and access the event. Here's an example of
such (very contrived example):

fucntion mousedownHandle r(obj) {
if (!e) e = window.event;
this.style.top = e.clientY +'px';
}

This works in Safari as it knows the event as e and I can get it for M$IE
with the window.event. How do I go about accessing it in Firefox?
BTW, I can't readily modify the CMS nor does the customer want to change
CMS.
--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESI S(dot)COM

"Well my son, life is like a beanstalk, isn't it?"
Jun 22 '07 #1
1 1484
On Jun 22, 8:39 pm, VAXman- @SendSpamHere.O RG wrote:
I have code which is created from a content mamagement system. It places
some handlers on tags with in-line registration:

<tag... onmousedown="mo usedownHandler( this);" ...>

I want to modified the handler and access the event. Here's an example of
such (very contrived example):

fucntion mousedownHandle r(obj) {
if (!e) e = window.event;
As e is (most probably[1]) undefined, the test is always true. A
global variable e is created and its value set as a reference to the
result of evaluating the expression "window.eve nt".

In the IE event model, an event object is available as a property of
the window object. Safari partially supports this model, hence in the
above code e is given a reference to the event object.

Firefox follows the Netscape model for event handling where the event
object must be passed to the function, it isn't available as a global
property.
this.style.top = e.clientY +'px';

}

This works in Safari as it knows the event as e
No, it doesn't. See above.
and I can get it for M$IE
with the window.event.
Which is how Safari gets it too.

How do I go about accessing it in Firefox?
You must pass a reference to the event object when calling the
function.

BTW, I can't readily modify the CMS nor does the customer want to change
CMS.
Then, in polite terms, you're screwed. :-)

One solution is to call the handler using:

<... onmousedown="mo usedownHandler( event);" ...>

Then you can get the element using the event object:

function mousedownHandle r(evt) {
var tgt = evt.target || evt.srcElement;

// In some browsers tgt may be a #text node
if (tgt.nodeType == 3) tgt = tgt.parentNode;
...
}

But that requires modification of the CMS. You might try modifying
the inline handlers to pass the event object as an additional last
argument:

<... onmousedown="mo usedownHandler( this, event);" ...>

and use:

function mousedownHandle r(obj, evt) {

// evt is the event object in both models
// obj is the element that has the handler

}

So existing functions aren't affected, they'll just ignore the extra
parameter.

You can read about events here:

<URL: http://www.quirksmode.org/js/introevents.html >

1. If you have created a global e somewhere else, e will be defined,
the test will evaluate to false and you won't get the current event
object.
--
Rob

Jun 23 '07 #2

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

Similar topics

4
3710
by: Mark Hoagland | last post by:
I've got a scenario with a web application where I must access the virtual directory being accessed from within the Application_OnStart event handler. Specifically, I have a series of IIS virtual directories which all point to the same set of ASP pages. However, since each virtual directory is a separate 'application', each has its own set data which must be cached. To detect which data must be cached for each virtual directory, I need to...
8
6083
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that uses message queues to pass pointers to Events between threads. In my app there are simple events that can be defined using an enum (for example an event called NETWORK_TIMEOUT) and more complex events that contain data (for example an event called...
5
5520
by: Andrei Pociu | last post by:
Inside a method some controls are created at runtime. I added an event handler to one of these controls: tracker.Scroll += new System.EventHandler(this.tracker_Scroll); So in the event handler I used unboxing to get access to the value of the TrackBar: private void tracker_Scroll(object sender, System.EventArgs e) {
2
2851
by: Boris Fortes | last post by:
I need to unhook event receiver as result of native C++ event. It unhooks successfully, but __raise does not return and throws access violation. Visual Studio 2003 How to reproduce: Consol Win32 exe project
2
2803
by: George | last post by:
I'm having a weird problem. When I double-click a Web server control that I have on my design-time Web form, such as a button, it puts the event handler in the Code Behind as a Private Sub routine. However, when I try to compile, I get an error saying that I can't access that event handler because it is Private. When I change the event handler from Private Sub to Public Sub, it works fine, but I know that is not the way it is supposed...
9
2442
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx"); ucline.Initializecontrol(line,alternate); Placeholder1.Controls.Add(ucline); }
7
3436
by: sam.m.gardiner | last post by:
I'm working with VB.NET events and I want a way to disconnect all the handlers of an event. I want to do this in the object that is the source of the event. This is slightly tricky in VB.Net as the eventing code is slightly hidden. when you use events in Vb.Net you type this: <code> Public event MyEvent() </code>
2
2068
by: =?Utf-8?B?TWF4IDFlNg==?= | last post by:
I have two events (a and b) each with its own handler. Unfortunately, event b is sometimes trigered by an action within a's handler causing a's handler to abort prematurely and service the b event. Is there a way to disable the b event inside the procedure for handling the a event? Is there another approach I should consider?
1
2857
by: Mike Thompson | last post by:
I have an event handler defined within a class. It has the following signature: static void XYZ_EventHandler (object sender, XYZEventArgs e) From within this event handler, I want to access the contents of a textbox on the form that is defined within the default Form1 class. Ordinarily, I would pass the form to any class member function as an argument, but because this is an event handler, I can't pass it.
2
19448
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
8109
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
8035
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8509
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
8188
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
6969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5502
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
4002
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...
0
4059
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.