¿Hablas history.pushState?

I’m not a fan of “Orange Is The New Black”, but I like this particular scene because it makes an important point: not everyone who looks Hispanic speaks Spanish, and vice versa.

Sometimes I think we try to be too “clever”, making inferences about another person’s capabilities based upon their appearance, their surnames, etc. Pro tip for you– the most reliable way to find out if someone speaks Spanish is to ask them: “¿hablas español?” If they look blankly at you and don’t respond, there’s no point in saying anything further in Spanish.

Likewise, we can be “too clever” when using JavaScript to access features in any given web browser.  I’ve seen web developers use clever tricks to determine which version of Internet Explorer, for example, they are dealing with, and then come up with a workaround for the cool thing they are trying to do. And it even works for a while– until the next version of Internet Explorer comes out and breaks the clever “which version of IE am I dealing with here?” trick they have been relying upon. And that’s when you start seeing code that works in Internet Explorer 8, but breaks in Internet Explorer 9.

Wouldn’t it be nice if we could just ask the browser, “Do you support the history.pushState feature?”  Actually, we can do just that, and it looks like this:

if (history.pushState) {
    history.pushState('', document.title, window.location.pathname);
else {
    window.location.hash = '';