Solved

Firefox/IE Event Handling Differences - attaching an event

Posted on 2007-03-22
5
1,735 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now