サイコロン

PCだったり自転車だったり趣味のこと

Youtube貼り付けでJSエラー

youtubeのタグ貼り付けのカスタムJSでエラーが出たので、対応策メモ。

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://www.youtube.com') does not match the recipient window's origin ('http://localhost').

参考はこちら
https://so-zou.jp/web-app/tech/web-api/google/youtube/player-api/iframe.htm#no21

ytPlayerの中のplayerVarsにorigineを付ければ直るらしいので、locationで取り込むよう追記。

playerVars: {
	"rel": 0,
	"autoplay": 0,
	"wmode": "opaque",
	'origin': location.protocol + '//' + location.hostname + "/"
}