Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.event is undefined 1

Status
Not open for further replies.

thewhistler1

Technical User
Jan 20, 2008
35
US
Hello all

I have an issue getting this to work in firefox, it seems to work fine in other browsers but firefox gives an error window.event is undefined when I try to use this. Any ideas?

Code:
<script>
document.onkeydown=function(evt) {
  var thelink
  if (window.event.keyCode==37) thelink='cb_prev'
  else if (window.event.keyCode==39) thelink='cb_next'
  else return
  document.getElementsByName(thelink)[0].onclick()
}
</script>
 
Firefox doesn't know what window.event is. It uses just the event object. So you need to do a check to see what browser is being used, and use the appropriate object.

Code:
var myevent=window.event? event : e; 

if(myevent.keycode==37)
...





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top