comet_iframe.js 1.69 KB
var comet = {
    connection: false,
    iframediv: false,
    timer: 0,
    initialize: function (url) {
        if (!-[1,]) {
            // For IE browsers
            comet.connection = new ActiveXObject("htmlfile");
            comet.connection.open();
            comet.connection.write("<html>");
            comet.connection.write("<script>document.domain = '" + document.domain + "'");
            comet.connection.write("</html>");
            comet.connection.close();
            comet.iframediv = comet.connection.createElement("div");
            comet.connection.appendChild(comet.iframediv);
            comet.connection.parentWindow.comet = comet;
            comet.iframediv.innerHTML = "<iframe id='comet_iframe' name='comet_iframe' src='"+url+"'></iframe>";
            var comet_iframe = comet.connection.getElementById("comet_iframe");
            comet.timer = window.setInterval(function() {
                if (comet_iframe.readyState === "complete") {
                    comet_iframe.src = comet_iframe.src;
                }
            }, 1000 * 65);
        } else {
            comet.connection = document.createElement('iframe');
            comet.connection.onload = function () {
                comet.connection.src = comet.connection.src;
            }
            comet.connection.setAttribute('id', 'comet_iframe');
            comet.connection.setAttribute('src', url);
            comet.connection.style.display = "none";
            document.body.appendChild(comet.connection);
        }
    },
    onUnload: function () {
        if (comet.connection) {
            comet.connection = false; // release the iframe to prevent problems with IE when reloading the page
        }
    }
}