Facebook Callback appends '#_=_' to Return URL

前端 未结 23 1714
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 14:56

Facebook callback has started appending #_=_ hash underscore to the Return URL

Does anyone know why? What is the solution?

相关标签:
23条回答
  • 2020-11-22 15:30

    Major annoying, especially for apps that parse the URI and not just read the $_GET... Here's the hack I threw together... Enjoy!

    <html xmlns:fb='http://www.facebook.com/2008/fbml'>
    <head>
            <script type="text/javascript">
            // Get rid of the Facebook residue hash in the URI
            // Must be done in JS cuz hash only exists client-side
            // IE and Chrome version of the hack
            if (String(window.location.hash).substring(0,1) == "#") {
                    window.location.hash = "";
                    window.location.href=window.location.href.slice(0, -1);
                    }
            // Firefox version of the hack
            if (String(location.hash).substring(0,1) == "#") {
                    location.hash = "";
                    location.href=location.href.substring(0,location.href.length-3);
                    }
            </script>
    </head>
    <body>
    URI should be clean
    </body>
    </html>
    
    0 讨论(0)
  • 2020-11-22 15:31

    Facebook uses a frame and inside of it everything functions using AJAX communication. The biggest problem in this case is preserving the current page state. As far I understand, Facebook decided to use simulated anchors. This means if you clicked somewhere, they simulate that as an anchor inside of your page, and when the AJAX communication starts, they change the anchor bit of your URL as well.

    This solution helps you normally when you try to reload the page (not ENTER, press F5), because your browser sends the whole URL with anchors to the Facebook server. Therefore Facebook picks up the latest state (what you see) and you are then able to continue from there.

    When the callback returns with #_=_ it means that the page was in its basic state prior to leaving it. Because this anchor is parsed by the browser, you need not worry about it.

    0 讨论(0)
  • 2020-11-22 15:31

    Using Angular 2 (RC5) and hash-based routes, I do this:

    const appRoutes: Routes = [
      ...
      {path: '_', redirectTo: '/facebookLoginSuccess'},
      ...
    ]
    

    and

    export const routing = RouterModule.forRoot(appRoutes, { useHash: true });
    

    As far as I understand, the = character in the route is interpreted as part of optional route parameters definition (see https://angular.io/docs/ts/latest/guide/router.html#!#optional-route-parameters), so not involved in the route matching.

    0 讨论(0)
  • 2020-11-22 15:31

    The easiest and clean solution to remove "#_=_" (PHP):

    Instead of "header("Location: xxx.php");" to use "echo ("location.href = 'xxx.php';");"

    0 讨论(0)
  • 2020-11-22 15:32

    A change was introduced recently in how Facebook handles session redirects. See "Change in Session Redirect Behavior" in this week's Operation Developer Love blog post for the announcement.

    0 讨论(0)
提交回复
热议问题