【发布时间】:2017-06-20 01:31:53
【问题描述】:
我有一个实现 youtube iframe api 的 iframe。一旦我将该 iframe src 更改为另一个视频 src(非 youtube),该 api 将继续无限地向新来源发出 postMessage 请求。
我已将其范围缩小到这段代码:
g.C = function(a) {
a.id = this.g;
a.channel = "widget";
a = ab(a);
var b = this.b;
var c = jb(this.a.src);
b = 0 == c.indexOf("https:") ? [c] : b.b ? [c.replace("http:", "https:")] : b.f ? [c] : [c, c.replace("http:", "https:")];
if (!this.a.contentWindow) throw Error("The YouTube player is not attached to the DOM.");
for (c = 0; c < b.length; c++) try {
this.a.contentWindow.postMessage(a, b[c])
} catch (d) {
if (d.name && "SyntaxError" == d.name) ob(d, "WARNING");
else throw d;
} };
连续发送this.a.contentWindow.postMessage(a, b[c])而不检查内容窗口的目的地。
有没有办法在播放器不再需要时将其销毁,这样这个 postMessage 就不会发送到其他来源?
谢谢, 杰克
【问题讨论】: