Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Created May 3, 2011 15:25
Show Gist options
  • Select an option

  • Save nathansmith/953533 to your computer and use it in GitHub Desktop.

Select an option

Save nathansmith/953533 to your computer and use it in GitHub Desktop.
Fixes IE10's broken path
// After some brainstorming with coworker Ara Pehlivanian,
// we came up with this monkey-patch for IE10, to help it
// normalize pathname to work like all other browsers.
//
// This forces path to be equal to "/foo/bar" regardless
// of what window.location.pathname actually resolves to:
//
// -- "/foo/bar" = Correct in all other browsers.
// -- "foo/bar" = Incorrect in IE10.
var path = ('/' + window.location.pathname).replace('//', '/');
@bernhard-hofmann
Copy link

Seems a bit inefficient to prefix pathname and then undo that again in every browser besides IE10. How about this:

var path = window.location.pathname;
if (path[0] !== '/') {
path = '/' + path;
}

See comparison here: http://jsperf.com/replace-vs-rewrite

@nathansmith
Copy link
Author

If I were reassigning the variable in a loop, I'd definitely speed-optimize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment