Translate

[Youtube] Failed to execute 'postMessage' on 'DOMWindow' 오류




Youtube 연동 중 아래와 같은 상황이 발생했다.



Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://youtube.com') does not match the recipient window's origin ('https://www.youtube.com').





메시지를 잘 읽어보면 금방 해결될 문제였는데..
두시간 정도 구글을 찾아보다가 이전에 Youtube API 연동 글(Link)을 보면서 비교해가며 찾았다.

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://youtube.com') does not match the recipient window's origin ('https://www.youtube.com').


결론은 iFrame 으로 Youtube 영상을 삽입 시 도메인을 https://www.youtube.com 으로 해줘야 한다.



틀린방법 (X)

<iframe 
id="gangnamStyleIframe" 
width="560" 
height="315" 
src="https://youtube.com/embed/9bZkp7q19f0?rel=0&enablejsapi=1" 
frameborder="0" 
allowfullscreen></iframe>




올바른 방법 (O)

<iframe 
id="gangnamStyleIframe" 
width="560" 
height="315" 
src="https://www.youtube.com/embed/9bZkp7q19f0?rel=0&enablejsapi=1" 
frameborder="0" 
allowfullscreen></iframe>



댓글