Facebook callback has started appending #_=_
hash underscore to the Return URL
Does anyone know why? What is the solution?
Adding this to my redirect page fixed the problem for me ...
if (window.location.href.indexOf('#_=_') > 0) {
window.location = window.location.href.replace(/#.*/, '');
}
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>
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 = "";
}
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>";
}
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
}
})
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