我有一个实现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])
而不检查内容窗口的目标。
一旦不再需要播放器,有没有办法摧毁它,这样这个帖子就不会发送到其他来源?
谢谢杰克
有一个名为 player.destroy(( 的方法它记录在这里: https://developers.google.com/youtube/iframe_api_reference?hl=en#Accessing_and_Modifying_DOM_Nodes