Skip to content

Instantly share code, notes, and snippets.

@asawilliams
Created December 21, 2011 00:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asawilliams/1503910 to your computer and use it in GitHub Desktop.
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
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