Created
May 3, 2011 15:25
-
-
Save nathansmith/953533 to your computer and use it in GitHub Desktop.
Fixes IE10's broken path
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
| // 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('//', '/'); |
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
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