Technologies Ignited

Technologies Ignited

window.event does not work in FireFox

leave a comment »

window.event does not work well in FireFox. So if you are using something like this:

<textarea onkeypress="onButtonPressed()"></textarea>
function onButtonPressed()
{
	var key = window.event.keyCode;
	var shift = window.event.shiftKey;
	//DO SOMETHING
}

you will have problems. Here’s how to solve this problem:

<textarea onkeypress="onButtonPressed(event)"></textarea>

and define your javascript function the following way:

function onButtonPressed(event)
{
	if(event)
	{
		var key = event.keyCode;
		var shift = event.shiftKey;
	}
	else
	{
		var key = window.event.keyCode;
		var shift = window.event.shiftKey;
	}
	//DO SOMETHING
}

Written by wyand

25 April 2012 at 14:22

Posted in JavaScript

Tagged with ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: