title: Youtube API - Failed to execute 'postMessage' on 'DOMWindow'
body: <p>I'm trying to start a youtube video when a modal is opened and not progress to the next page until it is completed.</p>
  
  <p>My script below works in Chrome but produces this error in Firefox and Edge.</p>
  
  <blockquote>
    <p>Failed to execute 'postMessage' on 'DOMWindow': The target origin
    provided ('<a href="https://www.youtube.com" rel="noreferrer">https://www.youtube.com</a>') does not match the recipient
    window's origin ('<a href="http://example.com" rel="noreferrer">http://example.com</a>').</p>
  </blockquote>
  
  <p><strong>Javascript</strong>
      </p>
  
  <pre><code>&lt;script src="http://www.youtube.com/player_api"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
      // autoplay video
      function onPlayerReady(event) {
          event.target.playVideo();
      }
  
      // when video ends
      function onPlayerStateChange(event) {        
          if(event.data === 0) {          
              alert('Thank you for watching - Click OK to see your results');
          }
      }
  
  &lt;/script&gt;
  
  &lt;script language="JavaScript"&gt;
      $(document).ready(function() {
          $('#post_form').submit(function() { // catch the form's submit event
              $("#adModal").modal("show");
              var time = $('#adtime').val();
              //startCountdownTimer(time) ;
  
              // create youtube player
              var player;
              player = new YT.Player('player', {
                  width: '640',
                  height: '390',
                  videoId: 'EF-jwIv1w68',
                  host: 'http://www.youtube.com',
                  events: {
                      onReady: onPlayerReady,
                      onStateChange: onPlayerStateChange
                  }
              });
  
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>I have reviewed <a href="https://stackoverflow.com/questions/27573017/failed-to-execute-postmessage-on-domwindow-https-www-youtube-com-http">this question/answer</a> but cannot seem to get it working with my code by amending the http / https.</p>