为了更清楚,我让它变得简单(所以我们假设 iframe.attr() 将在之前的加载完全完成后被调用):
var iframe = $("iframe");
var counter = 0;
var trackLoads = function(){
console.log("I was loaded:" + counter);
counter += 1;
};
iframe.load(trackLoads);
iframe.attr("src","http://stackoverflow.com/");
iframe.attr("src","http://localhost:9081/mobile/api/content/badPath"); //returns 204 No Content
iframe.attr("src","http://stackoverflow.com/");
控制台日志如下所示:
I was loaded:1
I was loaded:2
当 iframe 从 stackoverflow.com 加载新内容时,它会触发回调“trackLoads”,但由于某种原因,iframe 永远不会触发 204 No Content 的回调。
iframe 更改“src”属性后如何检测“204 No Content”?