Last active
August 29, 2015 14:06
-
-
Save tytskyi/c334778653aebe535c1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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