Solved

Firefox/IE Event Handling Differences - attaching an event

Posted on 2007-03-22
5
1,742 Views
Last Modified: 2008-01-09
I have some code which works in IE, but the event does not get attached in Firefox. Any ideas as to the equivalent in Firefox?

<script language="javascript">

document.getElementById('Player1').attachEvent('PlayStateChange', GetPlayState);

function GetPlayState()
{
            if (document.getElementById('Player1').playState==8)
            location.replace('/media2007/videoissues.asp');

}
</script>
0
Comment
Question by:fsbsupport
  • 2
5 Comments
 
LVL 4

Accepted Solution

by:
Cyber-Drugs earned 500 total points
ID: 18771709
You need addEventListener('click', myfunction, false)
0
 
LVL 4

Expert Comment

by:Cyber-Drugs
ID: 18771714
Extra information on the subject can be found here:

http://www.scottandrew.com/weblog/articles/cbs-events
0
 
LVL 15

Expert Comment

by:stanscott2
ID: 18773068
Do it like this (via Scott Andrew)

function addEvent(elm,evType,fn,useCapture) {
     if (elm.addEventListener) {
          elm.addEventListener(evType, fn, useCapture);
          return true;
     } else if (elm.attachEvent) {
          var r = elm.attachEvent('on' + evType, fn);
          return r;
     } else {
          elm['on' + evType] = fn;
     }
}
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now