Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prevent default handling #121

Open
drubb opened this issue Jul 25, 2016 · 3 comments
Open

How to prevent default handling #121

drubb opened this issue Jul 25, 2016 · 3 comments

Comments

@drubb
Copy link

drubb commented Jul 25, 2016

I'm not sure how to prevent the default handling for key pressures, at least it doesn't work for me. I've tried to figure this out from the docs, and ended up with the following code (example):

var scope = document.getElementById("page");
var options = {
    prevent_default  : true  
};
var listener = new window.keypress.Listener(scope, options);
listener.simple_combo("ctrl o", function() {
   alert("You pressed ctrl and o");
});

This will display the message, however the browser's default behaviour (open a file dialog) is triggered, too. Same for e.g. ctrl+f (opens find dialog).

Thanks a lot,
Boris

@drubb
Copy link
Author

drubb commented Jul 25, 2016

Just found out that this doesn't work in conjunction with alert. If I replace this by console.log, everything is fine, the default event won't be triggered. The default code without parameters is ok, too:

var listener = new window.keypress.Listener();
listener.simple_combo("ctrl o", function() {
   console.log("You pressed ctrl and o");
});

So maybe this is a special case.

@dmauro
Copy link
Owner

dmauro commented Jul 25, 2016

So all combos will prevent the default behaviors by default (the prevent_default is for all constituent keys). It looks like the browser is doing some magic and doesn't like that the JS is throwing an alert maybe? What browser is this in?

@drubb
Copy link
Author

drubb commented Jul 25, 2016

Firefox 47.0.1 (Windows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants