This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling events in Javascript

 
Rakesh Maddala
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And how are you handling them now?

Eric
 
Rakesh Maddala
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rakesh Maddala
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prototype will likely require more code changes than jQuery.

Information on Prototype can be found here.
 
Noms Dom
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should try Dojo. It should be pretty easy using dojo.connect
 
Rakesh Maddala
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic