-
Notifications
You must be signed in to change notification settings - Fork 968
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
Does Mousetrap support catch event in iframe? #107
Comments
Mousetrap events bound to the parent page will not trigger in an iframe and vice versa. Mousetrap events bound in the iframe should fire when the iframe has focus. If the text editor uses an input or text area then the mousetrap class should be applied to that element and not the body. Alternatively you could try the the bind global plugin. If you want to have keyboard events on the parent page trigger things to happen in the iframe or the other way around you could bind the events in one place and then communicate between the frames using post message. See http://viget.com/extend/using-javascript-postmessage-to-talk-to-iframes |
You can create this function in mousetrap.js and call it every time to bind keys in iframe Mousetrap.init = function(el){
if (el == undefined) {
el = document;
}
_addEvent(el, 'keypress', _handleKeyEvent);
_addEvent(el, 'keydown', _handleKeyEvent);
_addEvent(el, 'keyup', _handleKeyEvent);
} |
We can add a newly exposed method to support this use case? Such as the below // Exposed on the `Mousetrap` object
bindEvents: function(el) {
_addEvent(el, 'keypress', _handleKeyEvent);
_addEvent(el, 'keydown', _handleKeyEvent);
_addEvent(el, 'keyup', _handleKeyEvent);
} |
My fork, https://www.npmjs.org/package/combokeys, has this feature:
And then your |
I have a rich text editor in my app, the editor is implemented as a
iframe
, i try to catch event in it but seem no effect(i added the "mousetrap" as class).The text was updated successfully, but these errors were encountered: