Jump to content

Keyboard shortcuts to activate buttons


jeferod83
 Share

Recommended Posts

Hi guys,I was trying to call some buttons from my webpage simply by pressing the desired key, for each button, from the keyboard.For example:I have a form, with one text field called Person, and 3 buttons called Find, Add and Cancel. When I press Find, i'll submit the form; Add, simply redirect the browser to other page, and Cancel goes home. I want to activate the Find button by pressing F1, Add with F2 and Cancel with F3.Finding on google, I've found a library called shortcut.js, which can be found at http://www.openjs.com/scripts/events/keyboard_shortcuts/ and that can be used by calling the function:

<script>shortcut.add("F1",function(){	document.getElementById("buttonFind").click();});shortcut.add("F2",function(){	document.getElementById("buttonAdd").click();});shortcut.add("F3",function(){	document.getElementById("buttonCancel").click();});</script>

So, theoretically, the shortcuts are ready to be called, but only the submit button (F1) works fine. F2 and F3 does nothing. If I put an alert box in one of these, the alert appears, but there is no redirection. When I press manually the button using the mouse, it works fine.This button I is writen as follow:

<input id="buttonCancel" type="button" onmouseup="window.open("http://www.google.com");">

Anybody have an idea to make my shortcuts works fine?

Link to comment
Share on other sites

Your event is the mouseup event, but you're calling the click event. Change the handler to use onclick instead of onmouseup.
Yeah man! Tks!!! Works fine, but the browser has blocked the window.open event =(((Is there a way to circumvent this?
Link to comment
Share on other sites

Not from Javascript, you would need to change browser settings. There may be another way to open the window that would avoid the popup blocker, or else you just need to make sure your users know that they need to allow popups on your site.

Link to comment
Share on other sites

Not from Javascript, you would need to change browser settings. There may be another way to open the window that would avoid the popup blocker, or else you just need to make sure your users know that they need to allow popups on your site.
So, when I press the button manually with the mouse, the new window isn't blocked by the browser, but when I press F2, it happens.This happens because the javascript was that called?
Link to comment
Share on other sites

Yeah, because the browser can't tell that you've specifically asked for the window. It works on click because it knows that you've just clicked on something, so it allows the popup that results. Popup blockers try to stop popup windows that were opened automatically, so this is a case of the browser not being able to tell that the popup was opened from user interaction instead of automatically.

Link to comment
Share on other sites

Yeah, because the browser can't tell that you've specifically asked for the window. It works on click because it knows that you've just clicked on something, so it allows the popup that results. Popup blockers try to stop popup windows that were opened automatically, so this is a case of the browser not being able to tell that the popup was opened from user interaction instead of automatically.
I understand. Thanks for all my friend!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...