Why is window.event not working?

It worked, but now I get:

window.event is undefined 

From this simple code that worked:

 function checkKey() { if (window.event.keyCode != 9) { document.actionForm.saveStatus.value = "Not saved"; } } 

Why can't I use window.event anymore?

0
source share
3 answers

window.event is a proprietary Microsoftism.

The standard way to access event data is through the first argument of the event handler function.

+4
source
 function checkKey(e) { var evt = e || window.event, keyPressed = evt.which || evt.keyCode; if (keyPressed != 9) { document.actionForm.saveStatus.value = "Not saved"; } 
+2
source

You can standardize the check as follows:

 function checkKey(e) { var evt = e || window.event; if (evt.keyCode != 9) { document.actionForm.saveStatus.value = "Not saved"; } } 
+1
source

Source: https://habr.com/ru/post/956455/


All Articles