Skip to content

Commit a1c1a3a

Browse files
committed
Merge pull request #71 from bitsoglass/legacy_browser
Alternative to window.addEventListener for IE 8
2 parents 6424893 + 6a32081 commit a1c1a3a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

modules/stores/URLStore.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var invariant = require('react/lib/invariant');
33
var warning = require('react/lib/warning');
44

55
var CHANGE_EVENTS = {
6-
hash: 'hashchange',
6+
hash: (window.addEventListener) ? 'hashchange' : 'onhashchange',
77
history: 'popstate'
88
};
99

@@ -139,7 +139,11 @@ var URLStore = {
139139
if (location === 'hash' && window.location.hash === '')
140140
URLStore.replace('/');
141141

142-
window.addEventListener(changeEvent, notifyChange, false);
142+
if (window.addEventListener) { //check for IE 8
143+
window.addEventListener(changeEvent, notifyChange, false);
144+
} else {
145+
window.attachEvent(changeEvent, notifyChange);
146+
}
143147

144148
notifyChange();
145149
},
@@ -153,7 +157,11 @@ var URLStore = {
153157

154158
var changeEvent = CHANGE_EVENTS[_location];
155159

156-
window.removeEventListener(changeEvent, notifyChange, false);
160+
if (window.addEventListener) {
161+
window.removeEventListener(changeEvent, notifyChange, false);
162+
} else {
163+
window.detachEvent(changeEvent, notifyChange);
164+
}
157165

158166
_location = null;
159167
},

0 commit comments

Comments
 (0)