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

前端 未结 23 1716
爱一瞬间的悲伤
爱一瞬间的悲伤 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:26

    Adding this to my redirect page fixed the problem for me ...

    if (window.location.href.indexOf('#_=_') > 0) {
        window.location = window.location.href.replace(/#.*/, '');
    }
    
    0 讨论(0)
  • 2020-11-22 15:26

    I use this one, to delete '#' symbol as well.

    <script type="text/javascript">
        if (window.location.hash && window.location.hash == '#_=_') {
            window.location.href = window.location.href.split('#_=_')[0];
        }
    </script>
    
    0 讨论(0)
  • 2020-11-22 15:26

    For those who are looking for simple answer

    if (window.location.hash === "#_=_"){
        history.replaceState 
            ? history.replaceState(null, null, window.location.href.split("#")[0])
            : window.location.hash = "";
    }
    
    0 讨论(0)
  • 2020-11-22 15:27

    For me, i make JavaScript redirection to another page to get rid of #_=_. The ideas below should work. :)

    function redirect($url){
        echo "<script>window.location.href='{$url}?{$_SERVER["QUERY_STRING"]}'</script>";        
    }
    
    0 讨论(0)
  • 2020-11-22 15:28

    if you want to remove the remaining "#" from the url

    $(window).on('load', function(e){
      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
      }
    })
    
    0 讨论(0)
  • 2020-11-22 15:29

    This can become kind of a serious issue if you're using a JS framework with hashbang (/#!/) URLs, e.g. Angular. Indeed, Angular will consider URLs with a non-hashbang fragment as invalid and throw an error :

    Error: Invalid url "http://example.com/#_=_", missing hash prefix "#!".
    

    If you're in such a case (and redirecting to your domain root), instead of doing :

    window.location.hash = ''; // goes to /#, which is no better
    

    Simply do :

    window.location.hash = '!'; // goes to /#!, which allows Angular to take care of the rest
    
    0 讨论(0)
提交回复
热议问题