Place the following code in the element where the key press should be handled. If you want to open a layer, the code can not be in that same layer. Add it to (already) visible banner/layer.
screenad.addEventListener(screenad.PRELOAD_COMPLETE, function() {
setTimeout(setFocus, 150);
window.addEventListener("focus", focusHandler);
window.addEventListener("keydown", keyDownHandler, false);
}
function setFocus() {
window.focus();
}
function focusHandler(e) {}
function keyDownHandler(e) {
e.preventDefault();
if (e.keyCode === 71) { // key G
screenad.shared.callMethod("showLayer"); //example action
screenad.event("key_g_pressed"); // for reporting
}
}
When the page loads, the element will get the focus through the setFocus function. When the user clicks on the page (not the ad with the code) the ad will lose focus. Make sure you add the keydown listener and the keydownHandler in all elements so the user can still press the key.
Comments
0 comments
Please sign in to leave a comment.