Reputation: 151
I'm using jQuery Hotkeys within an iframe (iFrame A), on a page with two iFrames (A and B). When the focus is on A, the hotkeys work great. But I periodically have to click within iFrame B during use of the app.
How can I make the hotkeys work correctly for iFrame A even when it is not in focus?
Upvotes: 2
Views: 905
Reputation: 6492
I use iframes extensively with hotkeys. I make the hotkeys call a function called 'keyPressed' which determines what to do based on the key combination. If I'm on a page that is commonly loaded in an iframe, I will have the parent of the iframe bind extra hotkeys in the iframe when it loads. The iframe page's keyPressed function will try to pass a hotkey to the parent if it doesn't have a specific purpose. However, this only works if you have control over the iframes (they are part of your site).
//handles all key pressed events
function keyPressed(keyname) {
if (keyname == 'alt+s') {
SaveStdPage();
}
else if (keyname == 'alt+d') {
ClickButton('TrashBtn');
}
else {
//Pass hotkey to parent
try{
parent.keyPressed(keyname);
}
catch (ex) {
console.log(keyname);
}
}
}
Upvotes: 2