Capturing Cross-Origin iframe Events

前端 未结 1 524
孤独总比滥情好
孤独总比滥情好 2021-01-26 17:46

I have a website at domain A that contains an iframe used to show a video, which is hosted on YouTube. On the iframe load event, I am attempting to register for the keyup event

1条回答
  •  时光说笑
    2021-01-26 18:40

    The Same Origin Policy is preventing you from doing this.

    An origin consists of a scheme, port, protocol and domain. If these match, then JavaScript can be used to register events or to manipulate the DOM.

    If your site is http://example.com and the video is on http://example.org then cross domain scripting will not be possible because the domains do not match.

    It is possible for different origins to communicate, however they both need to opt into this functionality. postMessage is one such JavaScript function. However as you have no control of the origin running the video it cannot help you here.

    On solution for you may be to display the video inline on your page. This should enable you to capture events.

    0 讨论(0)
提交回复
热议问题