Created
December 21, 2011 00:13
-
-
Save asawilliams/1503910 to your computer and use it in GitHub Desktop.
This is to be used with History.js. It removes all the hash stuff added when a user uses an HTML4 browser
This file contains 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 hashUrl = window.location.hash; | |
if(hashUrl !== '') { | |
var url = hashUrl.replace('#',''); // remove # | |
var redirectUrl = window.location.protocol+'//'+window.location.host; | |
var path = window.location.pathname; | |
url = url.split('_suid')[0]; // remove everything after this | |
// if there are no vars, remove the ?& | |
if(url.indexOf('?') <= (url.length+2)) { | |
url = url.replace(/\?|&/g, ''); | |
} | |
// if there is a '.' then remove the | |
// last path | |
if(url.indexOf('.') === 0) { | |
// remove the '.' | |
url = url.replace('.', ''); | |
// remove the last path | |
path = path.slice(0,path.lastIndexOf('/')); | |
} | |
// create the new url to redirect to | |
redirectUrl += path+url; | |
window.location.href = redirectUrl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment