Skip to content

Commit 0516e3e

Browse files
Pavel VasekIgorMinar
Pavel Vasek
authored andcommitted
fix($location): prevent infinite digest error due to IE bug
If an app uses HTML5 mode and we open an html5 url on IE8 or 9 which don't support location href, we use location.replace to reload the page with the hashbang equivalent of the url but this fails with infinite digest. This is because location.replace doesn't update location.href synchronously on IE8 and 9. Closes angular#2802, angular#3305, angular#1417
1 parent 0a3ec5f commit 0516e3e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/ng/browser.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ function Browser(window, document, $log, $sniffer) {
123123
// URL API
124124
//////////////////////////////////////////////////////////////
125125

126-
var lastBrowserUrl = location.href,
127-
baseElement = document.find('base');
126+
var lastBrowserUrl = location.href,
127+
baseElement = document.find('base'),
128+
replacedUrl = null;
128129

129130
/**
130131
* @name ng.$browser#url
@@ -159,14 +160,20 @@ function Browser(window, document, $log, $sniffer) {
159160
baseElement.attr('href', baseElement.attr('href'));
160161
}
161162
} else {
162-
if (replace) location.replace(url);
163-
else location.href = url;
163+
if (replace) {
164+
location.replace(url);
165+
replacedUrl = url;
166+
} else {
167+
location.href = url;
168+
replacedUrl = null;
169+
}
164170
}
165171
return self;
166172
// getter
167173
} else {
174+
// the replacedUrl is a workaround for an issue with location.replace method isn't changing the location.href immediately
168175
// the replacement is a workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=407172
169-
return location.href.replace(/%27/g,"'");
176+
return replacedUrl || location.href.replace(/%27/g,"'");
170177
}
171178
};
172179

0 commit comments

Comments
 (0)