It seems that the Android browser doesn\'t properly implement window.location.replace
.
In most browsers, calling window.location.replace
wi
I had the same issue and ended up with code similar to chris suggestion, but I changed the if statement to use modernizr's feature detection. If you're not using modernizr the code would look something like this:
if(!!(window.history && history.replaceState)){
window.history.replaceState({}, document.title, base + fragment);
} else {
location.replace(base + fragment);
}
Unless you have a specific reason for device detection, feature detection is preferred since it basically supports all devices, even future ones.
To make it work across all/most mobile platforms check out this link.
Shows how to handle redirect for Android, iPad and iPhone.
Android uses document.location
whereas iOS supports window.location.replace
Will this work?
document.location.href = 'http://example.com/somePage.html';
You can try using the replaceState method on the history window.history
if (((navigator.userAgent.toLowerCase().indexOf('mozilla/5.0') > -1 && navigator.userAgent.toLowerCase().indexOf('android ') > -1 && navigator.userAgent.toLowerCase().indexOf('applewebkit') > -1) && !(navigator.userAgent.toLowerCase().indexOf('chrome') > -1))) {
window.history.replaceState({}, document.title, base + fragment);
} else {
location.replace(base + fragment);
}