Failed to execute 'postMessage' on 'DO

2019-01-03 15:48发布

This is the error message that I get:

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').

I've seen other similar problems where the target origin is http://www.youtube.com and the recipient origin is https://www.youtube.com, but none like mine where the target is https://www.youtube.com and the origin is http://localhost:9000.

  1. I don't get the problem. What is the problem?
  2. How can I fix it?

10条回答
走好不送
2楼-- · 2019-01-03 16:27

I believe this is an issue with the target origin being https. I suspect it is because your iFrame url is using http instead of https. Try changing the url of the file you are trying to embed to be https.

For instance:

var id = getId(url);
  return '//www.youtube.com/embed/' + id + '?showinfo=0&enablejsapi=1&origin=http://localhost:9000';
}

to be:

var id = getId(url);
  return 'https://www.youtube.com/embed/' + id + '?showinfo=0&enablejsapi=1&origin=http://localhost:9000';
}
查看更多
forever°为你锁心
3楼-- · 2019-01-03 16:27

I think the description of the error is misleading and has originally to do with wrong usage of the player object.

I had the same issue when switching to new Videos in a Slider.

When simply using the player.destroy() function described here the problem is gone.

查看更多
倾城 Initia
4楼-- · 2019-01-03 16:29

You can save into local files:

Into first file, player_api put this code:

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])}}());

Into second, find some like: this.a.contentWindow.postMessage(a,b[c]);

and change to:

if(this._skiped){
    this.a.contentWindow.postMessage(a,b[c]); 
}
this._skiped = true;

Of course, u can concatenate into one file - will be more efficient. This is not perfect solution, but it's works!

My Source : yt_api-concat

PS: Sorry, english is not my first languge.

查看更多
狗以群分
5楼-- · 2019-01-03 16:31

Just add the parameter "origin" with the URL of your site in the paramVars attribute of the player, like this:

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' },
}
查看更多
我想做一个坏孩纸
6楼-- · 2019-01-03 16:34

I got the same error. My mistake was that the enablejsapi=1 parameter was not present in the iframe src.

查看更多
你好瞎i
7楼-- · 2019-01-03 16:39

Try using window.location.href for the url to match the window's origin.

查看更多
登录 后发表回答