iframe application for VKontakte on D3js draws all sorts of things, and for interactive listens to the keyboard - keydown events on the <body> element.

How to transfer focus to my iframe when loading an application so that keystrokes immediately start to get into my script?

After the page is finished loading the VK with the application, pressing the space, for example, scrolls the page down, and JS does not receive this event. We have to offer the user to click the mouse in the iframe in order for the keyboard commands to start working.

The <svg> DOM element cannot be focused on: " TypeError: svgnode.focus is not a function ". Adding attribute focusable=true did not change anything. document.activeElement has the <body> value of this iframe, but the space scrolls the entire page, instead of the actions in my js-app.

Upd. if you create a text field, you can give it focus (). And then my script starts to catch keystrokes (which appear in the field). Those. desired is possible. It remains to grope how. Do not keep the same form field only for catching the focus.


Upd. October 7th. Still (again) relevant question. All the same: VKontakte iFrame application, FireFox (Mac). It is necessary to somehow start immediately catching keystrokes from iFrame - without additional actions by the user. In particular, on the arrows.

To the last comment @Eicto : after uncommenting that code in FF did not work.

0