这是我收到的错误消息:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided
('https://www.youtube.com') does not match the recipient window's origin
('http://localhost:9000').
我还看到了其他类似的问题,其中目标的原点是http://www.youtube.com
和接收者的原点是https://www.youtube.com
,而我的目标https://www.youtube.com
和目标的原点是http://localhost:9000
。
我认为这与目标来源有关https
。我怀疑是因为你使用的是iFrame网址,http
而不是https
。尝试更改要嵌入为的文件的url https
。
例如:
'//www.youtube.com/embed/' + id + '?showinfo=0&enablejsapi=1&origin=http://localhost:9000';
成为:
'https://www.youtube.com/embed/' + id + '?showinfo=0&enablejsapi=1&origin=http://localhost:9000';
这似乎奏效了。谢谢!所以,问题是
http
对https
?域名不同(YouTube与本地主机)无关紧要吗?目标原点与接收者原点到底是什么?您说的如何更改收件人的来源(我的URL仍然是localhost:9000)?该错误有点误导。实际上,这与您在场无关
localhost:9000
。问题实际上出在您使用youtube-api的方式上。当您tag.src = "https://www.youtube.com/iframe_api";
在代码中声明api时,就是在告诉youtube您要使用ssl。因此,我建议您将更改更改为使用ssl来请求视频。错误只是说您混用了ssl和non-ssl调用。当我尝试在dom中移动iframe时遇到了这个问题。
playerEl = document.querySelector('iframe#ytplayer'); anotherEl.appendChild(playerEl); // yt complains on subsequent api calls
如果我使用JavaScript加载YouTube播放器怎么办?
对于youtube更改为https://,而我的域为https://仍无法解决我的问题。无法在“ DOMWindow”上执行“ postMessage”:提供的目标原点(“ youtube.com ”)与收件人窗口的原点(“ test.dev ”)不匹配。