Skip to content

Instantly share code, notes, and snippets.

@sadasant
Created January 25, 2017 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadasant/8ec220c07764c36180f885cb11f934c7 to your computer and use it in GitHub Desktop.
Save sadasant/8ec220c07764c36180f885cb11f934c7 to your computer and use it in GitHub Desktop.
Duranda's History checkUrl fix
/**
* Checks the current URL to see if it has changed, and if it has, calls `loadUrl`, normalizing across the hidden iframe.
* @method checkUrl
* @return {boolean} Returns true/false from loading the url.
*/
function cleanFragment(s) {
return s
.replace(/%7E/g, "~")
.replace(/%21/g, "!")
.replace(/%2A/g, "*")
.replace(/%28/g, "(")
.replace(/%29/g, ")")
.replace(/%27/g, "'")
.replace(/%2D/g, "-")
.replace(/%2E/g, ".")
.replace(/%5F/g, "_")
}
history.checkUrl = function() {
var current = history.getFragment();
var compareCurrent = cleanFragment(current);
var historyFragment = cleanFragment(history.fragment);
if (compareCurrent === historyFragment && history.iframe) {
current = history.getFragment(history.getHash(history.iframe));
}
if (compareCurrent === historyFragment) {
return false;
}
if (history.iframe) {
history.navigate(current, false);
}
history.loadUrl();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment