From 2c2027e775b6fc9cc78647c3eefb5777d35ddff9 Mon Sep 17 00:00:00 2001 From: Orslumen Date: Fri, 8 Apr 2011 16:01:36 +0200 Subject: [PATCH] https://github.com/envjs/env-js/issues/15+16: Window.unload event and clear the timers --- envjs/platform/core.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/envjs/platform/core.js b/envjs/platform/core.js index 9d53a2cf..b9afc861 100644 --- a/envjs/platform/core.js +++ b/envjs/platform/core.js @@ -1376,6 +1376,20 @@ Envjs.exchangeHTMLDocument = function(doc, text, url) { event, frame = doc.__ownerFrame__, i; + // emit window.unload event, see https://github.com/envjs/env-js/issues#issue/16 + try { + if (doc === window.document) { + // console.log('triggering window.unload from core.js for url '+url); + event = doc.createEvent('HTMLEvents'); + event.initEvent('unload', false, false); + window.dispatchEvent( event, false ); + // clear the timers, see https://github.com/envjs/env-js/issues#issue/15 + Envjs.timers.length = 0; + } + } catch (eee) { + log.debug('window unload event failed %s', eee); + //swallow + } try { HTMLParser = HTMLParser || require('envjs/parser').HTMLParser; //do some cleanup so we can reuse the document