Skip to content

Instantly share code, notes, and snippets.

@tytskyi
Last active August 29, 2015 14:06
Show Gist options
  • Save tytskyi/c334778653aebe535c1b to your computer and use it in GitHub Desktop.
Save tytskyi/c334778653aebe535c1b to your computer and use it in GitHub Desktop.
var redirect = (function () {
var isFirefox = false;
var browser = window.navigator.userAgent;
var location = window.location;
var fixFirefoxHistory = function () {
var hash = window.location.hash;
var timestamp = Date.now();
if (isFirefox) {
hash = hash.length ? '' + hash + '-' + timestamp : timestamp;
location.hash = hash;
}
};
if (browser.toLowerCase().indexOf('firefox') > -1) {
isFirefox = true;
}
return function redirect (url) {
if (url) {
/** fix Chrome's back button */
location.hash = '';
/** fix Firefox's back button */
fixFirefoxHistory();
/** redirect with function or directly */
if (location.assign) {
location.assign(url);
} else {
location = url;
}
}
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment