Error loading youtube video in modal dialog with c

2019-06-19 01:58发布

问题:

I created a modal dialog to play youtube videos in. When the user clicks on a thumbnail image of the video it opens the dialog and injects the youtube iframe with this line of jQuery:

videoModal.html("<iframe class='youtube-player' id='youtube-player' type='text/html' width='640' height='385' src='http://www.youtube.com/embed/" + videoId + "?autoplay=1'  frameborder='0'></iframe>");

I get the following error only in Chrome, all other browsers do not complain

Unsafe JavaScript attempt to access frame with URL http://myDomain/ from frame with URL http://www.youtube.com/embed/MyVideoID?autoplay=1. Domains, protocols and ports must match.

Any ideas? Should I be worried about this? Any help or advice is appreciated.

回答1:

Assuming the player works, and this is a JavaScript warning in the console, I wouldn't worry about it. It just means that some script inside the iframe (at youtube) is attempting to access its parent window, which happens to be on a different domain. Cross-domain security prevents this from working, but it shouldn't affect your page.