aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Handling events in Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Handling events in Javascript" Watch "Handling events in Javascript" New topic
Author

Handling events in Javascript

Rakesh Maddala
Greenhorn

Joined: Aug 05, 2010
Posts: 10
Hi,

I am supporting an web application in Safari and Firefox. I have to handle events in w3c way. How should i go about it with a very minimal changes to the current code. Thanks.


Warm Regards
Rakesh Maddala
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
And how are you handling them now?

Eric
Rakesh Maddala
Greenhorn

Joined: Aug 05, 2010
Posts: 10
Hi Eric,

Thanks for your reply. I'm using IE and it does catches events into window object as "window.event". For firefox, this is not the case, we have to pass event object into the event handler function. This is very tedious job and wanted to find out a simple solution.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

Your best bet is to adopt a library such as jQuery or perhaps Prototype that abstracts the browser differences away for you. Otherwise you are going to be writing a lot of new code and a whole lot of conditional statements.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rakesh Maddala
Greenhorn

Joined: Aug 05, 2010
Posts: 10
Hi,

I have tried jQuery, which requires lot of rewiring for current code. I should try protyping browser differences. Well, will try that and let you know here. Thank you for valuable suggestion.
Rakesh Maddala
Greenhorn

Joined: Aug 05, 2010
Posts: 10
Can you please provide me some examples on how can we use prototype in javascript. It will be really helpful.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

Prototype will likely require more code changes than jQuery.

Information on Prototype can be found here.
Noms Dom
Greenhorn

Joined: Jan 30, 2009
Posts: 5
You should try Dojo. It should be pretty easy using dojo.connect
Rakesh Maddala
Greenhorn

Joined: Aug 05, 2010
Posts: 10
Hi Bear,

See, i'm doing this using following code:

earlier:

<input type="button" onclick="doThis()">

Now,

<input type="button" onclick="if(!isIE)window.event=event;doThis()">

So that i will be having window.event in all scopes. This has reduced a little amount of work for me. Going forward if am able to do "if(!isIE)window.event=event" in some place before going to doThis(), will make my life simpler. Any suggestions about this?

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61430
    
  67

There are many more differences, for example the properties in the event instance, across the browsers. A library such as jQuery normalizes all that for you. You can continue using if's all over the place, or adopt a library. The choice is yours.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handling events in Javascript