From: Matteo Nastasi (mop) Date: Sat, 7 Apr 2012 16:51:50 +0000 (+0200) Subject: workaround implemented to avoid IE7 scope reset X-Git-Url: https://mop.ddnsfree.com/gitweb/?p=xynt.git;a=commitdiff_plain;h=08d4ed7dda698da0d092bbd8a31c15bd2c447927 workaround implemented to avoid IE7 scope reset --- diff --git a/web/test-hs-rd.php b/web/test-hs-rd.php index 67bc876..bfa7544 100644 --- a/web/test-hs-rd.php +++ b/web/test-hs-rd.php @@ -1,13 +1,10 @@ - + - parent.allmythings = %d; - console.log(\"zorro \"+parent.allmythings); - - ", $i, $i); + if ($i != 18) { + printf("", $i, $i); } else { - printf("", $i, $i); + // exit(); + sleep(30); } if ($i == 0) printf("", $s); diff --git a/web/test-hs.php b/web/test-hs.php index 257d895..8d9082d 100644 --- a/web/test-hs.php +++ b/web/test-hs.php @@ -9,7 +9,7 @@ var allmythings="BEGIN"; window.onload = function () { var hs; console.log("zugu"); - hs = new http_streaming(document, console); + hs = new http_streaming(window, console); hs.start('test-hs-rd.php'); } diff --git a/web/xynt/xynt-http-streaming.js b/web/xynt/xynt-http-streaming.js index cb914e0..3988d1d 100644 --- a/web/xynt/xynt-http-streaming.js +++ b/web/xynt/xynt-http-streaming.js @@ -1,57 +1,94 @@ -function http_streaming(doc, cons) +function http_streaming(win, cons) { this.console = cons; - this.doc = doc; + this.doc = win.document; this.keepalive_old = -1; this.keepalive_new = -1; this.keepalives_equal = 0; - this.ifra = doc.createElement("iframe"); + this.ifra = this.doc.createElement("iframe"); this.ifra.style.visibility = "hidden"; - doc.body.appendChild(this.ifra); - // this.ifra.contentWindow.onload = function () { - // this.ifra.contentWindow.location.href = 'winstream_rdxxx.php'; - // } - + this.doc.body.appendChild(this.ifra); } http_streaming.prototype = { console: null, doc: null, ifra: null, + page: null, + wd_handle: null, keepalive_old: -1, keepalive_new: -1, keepalives_equal: 0, keepalives_eq_max: 6, watchdog_timeout: 2000, + watchable: false, + restart_n: 0, start: function(page) { - this.log("http_streaming:start"); + this.log("http_streaming:start restart: "+this.restart_n); + this.page = page; this.ifra.contentWindow.location.href = page; - setTimeout(function(obj) { obj.watchdog(); }, this.watchdog_timeout, this); + this.wd_handle = setTimeout(function(obj) { obj.log("tout1"); obj.watchdog(); }, this.watchdog_timeout, this); }, watchdog: function () { /* +this.keepalives_equal */ - this.log("hs::watchdog: start"); + this.log("hs::watchdog: start, cur equal times: "+this.keepalives_equal); + if (!this.watchable) { + do { + if (typeof(this.ifra.contentWindow.http_streaming) == 'undefined') + break; + /* + on IE7 the the window frame scope is cleaned after the href is set, so we wait + for a well know variable value before assign this object value to it (OO is a passion) + */ + if (this.ifra.contentWindow.http_streaming == "ready") { + this.ifra.contentWindow.http_streaming = this; + this.watchable = true; + } + } while (false); + } + this.log("hs::watchdog: this.keepalive_old: "+this.keepalive_old+" this.keepalive_new: "+this.keepalive_new); if (this.keepalive_old == this.keepalive_new) { this.keepalives_equal++; } else { + this.keepalive_old = this.keepalive_new; this.keepalives_equal = 0; } if (this.keepalives_equal > this.keepalives_eq_max) { this.log("hs::watchdog: MAX ACHIEVED "+this.keepalives_equal); + this.reload(); + return; } else { - setTimeout(function(obj) { obj.watchdog() }, this.watchdog_timeout, this); + this.wd_handle = setTimeout(function(obj) { obj.log("tout2"); obj.watchdog(); }, this.watchdog_timeout, this); } }, keepalive: function () { + this.log("hs::keepalive"); this.keepalive_new++; }, + abort: function () { + clearTimeout(this.wd_handle); + this.restart_n++; + this.log("hs::reload"); + this.watchable = false; + delete this.ifra; + }, + + reload: function () { + this.abort(); + this.keepalives_equal = 0; + this.ifra = this.doc.createElement("iframe"); + this.ifra.style.visibility = "hidden"; + this.doc.body.appendChild(this.ifra); + this.start(this.page); + }, + log: function (s) { if (this.console != null) { return (this.console.log(s));