Javascript Hotkey Implementation

Hello
I am trying to implement a hotkey on a web site. I can intercept a hotkey combination but I cannot get to implement a function other than alert.

The code I am using is

script type='text/javascript' language='javascript'>
		document.onkeyup = function(e)	
		{
			if (e.ctrlKey && e.altKey && e.which == 89)
			{
				alert("Ctrl + Alt + Y shortcut key combination was pressed");

				alert('aboutBox()');
				alert("Ctrl + Alt + Y shortcut key combination was pressed");
			}
		}
</script>

I am trying to get it to implement the about function but it will not. I know I am missing something but I do not know what or why. I would appreciate any pointers or help.

Thank you.

Firstly, you no longer need type='text/javascript', it’s default in HTML5; and we haven’t had to use language='javascript' for quite some time, so you can remove both attributes.

Is the function aboutBox() being defined prior to your document.onkeyup?

V/r,

^ _ ^

Thank you! Your comment regarding the aboutBox() function was spot on. I feel so silly but it happens from time to time. I was so busy trying to the hotkey code to work I forgot to include the function in the header file. I really appreciate the second set of eyes.

Regarding the attributes, yes. I just include them out of habit.

Again. Many thanks.

You’re alerting the string "aboutBox()" here; if you want to alert the result of the function aboutBox(), leave away the quotes:

function aboutBox () {
  return 'hello world'
}

alert(aboutBox()) // alerts "hello world"

Some things can be ‘hoisted’, but functions typically are not and must be placed prior to the event calling them. Glad you got it working.

V/r,

^ _ ^

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.