How do you prevent IE8 from escaping "#" as "%23" in URLs?

I'm using Javascript to dynamically set the window.location.href with URLs that sometimes contain "#" for anchor names (e.g. "/some/path/#anchorname")

Firefox/Safari/Chrome interpret this perfectly. Naturally, IE routinely replaces "#" with "%23", resulting in a completely incorrect URL (e.g. "/some/path/%23anchorname").