473,378 Members | 1,122 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,378 software developers and data experts.

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="mousedownHandler(this);" ...>
I want to modified the handler and access the event. Here's an example of
such (very contrived example):

fucntion mousedownHandler(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)TMESIS(dot)COM

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

<tag... onmousedown="mousedownHandler(this);" ...>

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

fucntion mousedownHandler(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.event".

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="mousedownHandler(event);" ...>

Then you can get the element using the event object:

function mousedownHandler(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="mousedownHandler(this, event);" ...>

and use:

function mousedownHandler(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
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...
8
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...
5
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...
2
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...
2
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...
9
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");...
7
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...
2
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....
1
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.