Saturday, December 19, 2009

ie vs ff on javascript

We all know how painful it is to deal with the standard differences when it comes to javascript programming across IE and Firefox. There can be many to be listed, but I’m going to list them out as a series of posts over time. These are going to be my findings, so correct any mistakes i may have.

Access DOM Object in an attached event
let’s say you have a link on the page that you want to attach an onclick event to
and assume addEvent is a method created to support both IE and FF

Under Firefox, if you want to access the linkObj, you can simply use “this”
linkObj.addEvent(”click”, function(){
alert(this.href);
})
Under IE, you can’t use “this” because “this” will referrer to the document object
instead, you have to use srcElement, and pass in e as an argument
linkObj.addEvent(”click”, function(e){
var thisObj=e.srcElement;
alert(thisObj.href);
});

3 comments:

  1. The thing about java in different platforms are the fundamental differences in codes for them.

    white label seo

    ReplyDelete
  2. And the same goes for other scripts and programming languages.
    web design perth

    ReplyDelete
  3. Right Finn and Melissa. Coding and other programming languages is essential for every web developer.
    los angeles seo

    ReplyDelete