客户端ajaxComplete调用生成无限iframe [英] Client-Side ajaxComplete Call Generating Infinite iframes
问题描述
好的,所以这是我的问题。我正在写一个Greasemonkey脚本在AJAXified网站上插入两个iframe,但是ajaxComplete被一个循环捕获并产生过多的iframe(有时是一个,有时是五个等等),gener。
Alright, so here is my issue. I'm writing a Greasemonkey script to insert two iframes on an AJAXified site, but ajaxComplete gets caught in a loop and generates an excess number of iframes (sometimes one, sometimes five, etc...), gener.
我已经完成了我的研究并且[我认为]我的问题是我没有正确地约束对文档的调用,但对此我不确定。我不确定你会怎么做比我已经有的不同。如果你们能指出我正确的方向,我将不胜感激。以下是有问题的代码:
I've done my research and [I think] my problem is that I'm not binding the call to the document properly, but of this I am unsure. I'm not sure how you would do it differently than I already have. If you guys could point me in the right direction I'd be grateful. Here is the offending code:
function OnLoadWidgets() {
var tempSC = document.createElement("div");
tempSC.id = "SCWidget";
tempSC.innerHTML = "..."
document.getElementById("content-right").appendChild(tempSC);
var tempMC = document.createElement("div");
tempMC.id = "MCWidget";
tempMC.innerHTML = "..."
document.getElementById("content-right").appendChild(tempMC);
}
unsafeWindow.jQuery(document).ajaxComplete(function()
{
var existingSCPlayer = document.getElementById("SCWidget");
if(typeof(existingPlayer) == "undefined")
{
OnLoadWidgets();
}
});
您可以在此处查看其余代码:
http://userscripts.org/scripts/show/127312
You can see the rest of the code here: http://userscripts.org/scripts/show/127312
也想利用这个机会感谢你们所有的辛勤工作。真的不能够感谢你。 stack == lifesaver
Also wanted to use this a chance to thank you guys for all your hard work. Can't thank you enough, really. stack == lifesaver
推荐答案
(1)目标网站 hypem.com ,使用自己的iframe,你的Greasemonkey脚本也将触发。
(1) The target site, hypem.com, uses its own iframes and your Greasemonkey script will fire on those also.
通过添加:
if (window.top != window.self) //-- Don't run on frames or iframes.
return;
靠近剧本顶部。
(2)代码中有一个变量名称拼写错误。 existingSCPlayer
与 existingPlayer
。
(3)优化重复检查以使其更具包容性。使用此代码:
(3) Refine the duplicate check to be a little more inclusive. Use this code:
unsafeWindow.jQuery (document).ajaxComplete ( function () {
var existingSCPlayer = document.getElementById ("SCWidget");
var existingMCPlayer = document.getElementById ("MCWidget");
if ( ! existingSCPlayer && ! existingMCPlayer) {
OnLoadWidgets();
}
} );
这篇关于客户端ajaxComplete调用生成无限iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!