There is not a way to detect an open connection from JS unless you write a wrapper for XmlHttpRequest
(or monkey patch it) that keeps track of opened connections.
Here's kidcapital's monkey patch, not sure if it's perfect, but it's a good start
(function() {
var oldOpen = XMLHttpRequest.prototype.open;
window.openHTTPs = 0;
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
window.openHTTPs++;
this.addEventListener("readystatechange", function() {
if(this.readyState == 4) {
window.openHTTPs--;
}
}, false);
oldOpen.call(this, method, url, async, user, pass);
}
})();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…