Ada*_*ner 139 javascript youtube youtube-api angularjs youtube-iframe-api
这是我得到的错误消息:
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').
Run Code Online (Sandbox Code Playgroud)
我已经看到了目标来源http://www.youtube.com和收件人来源的其他类似问题https://www.youtube.com,但没有一个像我的目标所在的地方https://www.youtube.com和原点http://localhost:9000.
Chr*_*lin 83
我认为这是目标来源的一个问题https.我怀疑这是因为你的iFrame网址正在使用http而不是https.尝试更改您要嵌入的文件的网址https.
例如:
'//www.youtube.com/embed/' + id + '?showinfo=0&enablejsapi=1&origin=http://localhost:9000';
Run Code Online (Sandbox Code Playgroud)
成为:
'https://www.youtube.com/embed/' + id + '?showinfo=0&enablejsapi=1&origin=http://localhost:9000';
Run Code Online (Sandbox Code Playgroud)
小智 19
只需在播放器"origin"的paramVars属性中添加带有网站网址的参数,如下所示:
this.player = new window['YT'].Player('player', {
videoId: this.mediaid,
width:'100%',
playerVars: { 'autoplay': 1, 'controls': 0,'autohide':1,'wmode':'opaque','origin':'http://localhost:8100' },
}
Run Code Online (Sandbox Code Playgroud)
M.A*_*yed 16
设置这似乎解决了它:
this$1.player = new YouTube.Player(this$1.elementId, {
videoId: videoId,
host: 'https://www.youtube.com',
Run Code Online (Sandbox Code Playgroud)
小智 8
您可以将JavaScript保存到本地文件中:
player_api将以下代码放入第一个文件中:
if(!window.YT)var YT={loading:0,loaded:0};if(!window.YTConfig)var YTConfig={host:"https://www.youtube.com"};YT.loading||(YT.loading=1,function(){var o=[];YT.ready=function(n){YT.loaded?n():o.push(n)},window.onYTReady=function(){YT.loaded=1;for(var n=0;n<o.length;n++)try{o[n]()}catch(i){}},YT.setConfig=function(o){for(var n in o)o.hasOwnProperty(n)&&(YTConfig[n]=o[n])}}());
Run Code Online (Sandbox Code Playgroud)
进入第二个文件,找到代码: this.a.contentWindow.postMessage(a,b[c]);
并替换为:
if(this._skiped){
this.a.contentWindow.postMessage(a,b[c]);
}
this._skiped = true;
Run Code Online (Sandbox Code Playgroud)
当然,您可以串联到一个文件中-效率更高。这不是一个完美的解决方案,但是可以!
我的资料来源:yt_api-concat
确保从 URL 加载,例如:
注意“origin”组件,以及“enablejsapi=1”。来源必须与您的域相匹配,然后它将被列入白名单并正常工作。
| 归档时间: |
|
| 查看次数: |
232423 次 |
| 最近记录: |