Skip to content

Commit

Permalink
envjs#15: Window.unload event and clear the timers
Browse files Browse the repository at this point in the history
  • Loading branch information
orslumen committed Apr 8, 2011
1 parent 80c79e3 commit 2c2027e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions envjs/platform/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c2027e

Please sign in to comment.