Discussions » Development

Can't make event listener work when iframe video is focused

§
Posted: 2022-07-23
Edited: 2022-07-23

No matter what I do when I click on the iframe and it get's focused I can't make any event listeners work and be trigged.

The script does detect the event listener n and l keypresses as long as I haven't clicked on the iframe and it is not focused.

Does anyone know how to fix this?

This script has to be used https://greasyfork.org/en/scripts/411391 so that you can test my script on this page for example https://www.crunchyroll.com/date-a-live/episode-11-past-sins-842798

This is my code so far https://greasyfork.org/en/scripts/448382-testy/code

*Check lines 66-80

§
Posted: 2022-07-28

https://pastebin.com/Ye7Kn2Vt

Anyone know what is the issue?

§
Posted: 2022-07-30

I think this is because each iframe has its own document and you need to add eventListeners to the iframes contentDocument?

See

https://stackoverflow.com/questions/68063629/window-addeventlistener-stops-working-once-iframe-is-loaded-inside-body

https://jsfiddle.net/7h0jfv3x/

§
Posted: 2022-08-05

@purplepinapples

The problem is that the iframe is from a different website and domain, so that is probably why the code below doesn't work

document.querySelector("#frame").contentWindow.addEventListener('keydown', function (e) {
console.log(e.target)
console.log('hi')
})

Post reply

Sign in to post a reply.