我有一个按钮激活的插件。代码如下:
function handleClick(state) {
activeTab = tabs.activeTab;
console.log('readystate: ' + activeTab.readyState);
if(activeTab.readyState != 'complete')
{
activeTab.on('load', function(){
activeTab.removeListener(this);
start();
});
}
else
start();
}
但是,每当我向选项卡询问其当前的readystate时,上述代码总会返回“complete”。我完全确定页面仍在加载,微调器仍在运行,我实际上已经使用XDebug启用了PHP断点,以确保我的页面永远不会完成加载,直到我想要它。根据{{3}},readystate应该是“loading”,因为PHP甚至没有完成,所以服务器没有发回任何HTML,所以甚至没有DOM。
更新:到目前为止我发现的是,在你收到第一个服务器响应之前,readystate会返回'complete'。一旦初始服务器响应返回浏览器,就绪状态就会变为“正在加载”。不知道该怎么做。
答案 0 :(得分:0)
而不是检查readyState属性检查progress属性,我怀疑在DOMContentReady之前readyState完成后触发,所以在完成后你可能需要为DOMContentReady
或load
添加一个事件listerner
var tab = gBrowser.loadOneTab('data:text/html,<div class="profilist-icon-build-1">backround of this span is of icon on desktop</div><input type="button" value="applyCss"><input type="button" value="removeCss"> Change File on Desktop to: <input type="button" value="Release Img"><input type="button" value="Beta Img"><input type="button" value="Aurora Img"><input type="button" value="Nightly Img">', {inBackground:false});
//start - listen for loadOneTab to finish loading per https://gist.github.com/Noitidart/0f076070bc77abd5e406
var mobs = new window.MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName == 'progress' && tab.getAttribute('progress') == '') {
//alert('tab done loading');
init();
mobs.disconnect();
}
});
});
mobs.observe(tab, {attributes: true});
//end - listen for loadOneTab to finish loading per https://gist.github.com/Noitidart/0f076070bc77abd5e406
function init() {
//run on load of the loadOneTab
var win = tab.linkedBrowser.contentWindow;
var doc = win.document;
var btns = doc.querySelectorAll('input[type=button]');
Array.prototype.forEach.call(btns, function(b) {
b.addEventListener('click', handleBtnClick, false);
});
}