From da23d4dd395ba529dfc4649ac7d4749f3d2430ee Mon Sep 17 00:00:00 2001 From: Amauri CHAMPEAUX Date: Fri, 27 Feb 2015 16:28:48 +0100 Subject: [PATCH] Prevent undefined error --- tarteaucitron.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tarteaucitron.js b/tarteaucitron.js index a91787c..bc6b1cc 100644 --- a/tarteaucitron.js +++ b/tarteaucitron.js @@ -50,14 +50,25 @@ var tarteaucitron = { }); } - XMLHttpRequest.prototype.open = function () { - this.addEventListener('load', function () { - if (typeof tarteaucitronProLoadServices === 'function') { - tarteaucitronProLoadServices(); + if (typeof XMLHttpRequest !== 'undefined') { + XMLHttpRequest.prototype.open = function () { + + if (window.addEventListener) { + this.addEventListener("load", function () { + if (typeof tarteaucitronProLoadServices === 'function') { + tarteaucitronProLoadServices(); + } + }, false); + } else { + this.attachEvent("onload", function () { + if (typeof tarteaucitronProLoadServices === 'function') { + tarteaucitronProLoadServices(); + } + }); } - }); - origOpen.apply(this, arguments); - }; + origOpen.apply(this, arguments); + }; + } } }, "load": function (params) {