Cross Browser Support for DOM Events

Cross Browser Support for DOM Events

Firefox follows the DOM standard and passes an event object to each event listener, however has the global event: windows.event.

Problem:
I wanted to fire a piece of javascript after the user keyed some text and pressed enter or clicked a button. The skeleton code is below:

<input id=”NewsletterEmail” value=”Email here” type=”text”
   onfocus=”javascript:this.value = ”;” class=”WiderLoginTextBox” />
<input value=”OK” type=”button”>

Solution:
Firstly to handle the click of the button I added a call to a javascript function to the button’s onclick event:

onclick=”javascript:return SubscribeToNewsletter(event);”
and the same call on the text box’s onkeypress event:

onkeypress=”javascript:return SubscribeToNewsletter(event);”

The javascript function code is below:

function SubscribeToNewsletter(e)
{
   var keycode;
   var el;
   if (!e)
   {
// ie does not pass the event as a parameter!
      e = window.event;
      el = e.srcElement; // ie uses the window.event.srcElement property
   }
   else
      el = e.target; // non-ie uses the window.event.target property
   keycode = e.which;
   if (keycode == 13 || el.type == “button”) // enter or button clicked?
   {
      RegisterForNewsletter(); // call another piece of javascript to do the work…
      return false;
   }
   else
      return true;
   }

0 responses to “Cross Browser Support for DOM Events”

  1. At this page, you can find various websites for CS:GO betting.
    We have collected a diverse lineup of gambling platforms centered around CS:GO players.
    Every website is handpicked to ensure safety.
    cs2 gambling website
    Whether you’re a CS:GO enthusiast, you’ll easily discover a platform that suits your needs.
    Our goal is to make it easy for you to access only the best CS:GO betting sites.
    Check out our list now and elevate your CS:GO playing experience!

Leave a Reply

Your email address will not be published. Required fields are marked *