Fix issue 322: calling destroy() results in an error in IE8
authorDan Vanderkam <danvk@google.com>
Mon, 13 Aug 2012 21:53:23 +0000 (17:53 -0400)
committerDan Vanderkam <danvk@google.com>
Mon, 13 Aug 2012 21:53:23 +0000 (17:53 -0400)
dygraph-utils.js

index e942f0c..dd8c620 100644 (file)
@@ -177,7 +177,12 @@ Dygraph.removeEvent = function addEvent(elem, type, fn) {
   if (elem.removeEventListener) {
     elem.removeEventListener(type, fn, false);
   } else {
-    elem.detachEvent('on'+type, elem[type+fn]);
+    try {
+      elem.detachEvent('on'+type, elem[type+fn]);
+    } catch(e) {
+      // We only detach event listeners on a "best effort" basis in IE. See:
+      // http://stackoverflow.com/questions/2553632/detachevent-not-working-with-named-inline-functions
+    }
     elem[type+fn] = null;
   }
 };