【发布时间】:2016-02-12 15:46:33
【问题描述】:
我收到关于 YouTube iFrame API 中的标头集的错误消息。我不相信以前发生过这种情况。
Refused to set unsafe header "Origin"
Wdwww-embed-player.js:225:275
$dwww-embed-player.js:228:375
(anonymous function)www-embed-player.js:1267
Jmwww-embed-player.js:870:162
Gqwww-embed-player.js:1266:557
wrwww-embed-player.js:1302:197
(anonymous function)F1CbO4TLzgI:9:14691
这似乎只发生在 iPhone 上(在 Chrome 和 Safari 中)。我使用的是最新的 iOS (9.2.1)
这是最后一个错误发生的代码:
//ln 1503
function Wd(a, b, c, d, e, f, h) {
function k() {
4 == (l && "readyState"in l ? l.readyState : 0) && b && nc(b)(l)
}
var l = Ud && Ud();
if (!("open"in l))
return null;
"onloadend"in l ? l.addEventListener("loadend", k, !1) : l.onreadystatechange = k;
c = (c || "GET").toUpperCase();
d = d || "";
l.open(c, a, !0);
f && (l.responseType = f);
h && (l.withCredentials=!0);
f = "POST" == c;
if (e = Xd(a, e))
for (var n in e)
l.setRequestHeader(n, e[n]), "content-type" == n.toLowerCase() && (f=!1);
f && l.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
l.send(d);
return l
}
这是我加载视频的代码:
var yt = document.createElement('div'),
_this = this,
id = this.videoID;
$(yt).attr('id', id);
this.container.append(yt);
this.el = new YT.Player(id, {
height: '100%',
width: '100%',
playerVars: {
'autoplay': 1,
'controls': 0,
'search': 0,
'showinfo': 0,
'autohide': 1,
'rel': 0,
'html5': 1
},
videoId: this.videoID,
events: {
'onReady': function(e) { _this.loadComplete(e); },
'onStateChange': function(e) { _this.stateChanged(e); },
'onError': function(e) { _this.error(e); }
}
});
this.timeout = setTimeout(function() {
_this.core.debug.log('YOUTUBE', 'CHECKTIMEOUT', _this);
if (!_this.isLoaded) {
_this.error();
}
}, TIMEOUT);
任何帮助或建议将不胜感激。
【问题讨论】:
-
也只是一个注释...桌面浏览器上不会出现此错误。
-
您能否提供一个完整的 jsfiddle 示例,以便我可以在 iPhone 上进行测试?
-
似乎 jsfiddle 甚至无法在我的 iPhone 上进行基本的嵌入...jsfiddle.net/n7gvsqb9/1
标签: youtube-api youtube-iframe-api