stackers
stackers

Reputation: 3279

Pressing space inside iframe scrolls outer page

I'm trying to submit a web game to itch which uses the space key. My game gets embedded on their website in an iframe. But when you press spaceon the embed page (even after clicking inside the iframe), it scrolls the parent page down.

I have this added to the keyup listener:

document.addEventListener('keyup', e => {
    e.preventDefault();
    e.stopPropagation();
    e.stopImmediatePropagation();
    handleInput(e);
    return false;
});

I tried changing the listener to be on the window, i tried the suggestion here: https://stackoverflow.com/a/63695716/929321

it's still scrolling the parent page every time, i dont know what to do

Upvotes: 0

Views: 122

Answers (1)

ympek
ympek

Reputation: 351

Try similar steps, but with keydown. Notice this behavior of space key is fired on keydown, not keyup.

Upvotes: 1

Related Questions