Last Updated: February 25, 2016
·
8.243K
· jasontorres

Facebook appending #_=_ to urls after authentication

I have an app that's using jquery.history.js to trigger a modal dialog for an item page instead of navigating to another page (imagine pinterest style navigation)

Now, I have a base path (usually the entry point) called /products

When clicking on a item, for example /products/some-product, it then triggers a modal dialog which fetches the data using a basic jQuery.get() and fills the modal with the content. When the dialog closes, the history does a (-1) which basically brings back the browser to /products without a page refresh using jquery.history.js

The problem is after authenticating with Facebook. The base path becomes a hash which eventually breaks the navigation.

A solution is simply removing the hash as stated here then everything seems back to normal

http://stackoverflow.com/questions/7131909/facebook-callback-appends-to-return-url

if (window.location.hash == '#_=_') {
    window.location.hash = ''; // for older browsers, leaves a # behind
    history.pushState('', document.title, window.location.pathname); // nice and clean
    e.preventDefault(); // no page reload
}

The modal navigation however is left for another topic. :)