13

My site lets users login via the Fb button, I'm using the FB / Parse.com JDK for this https://parse.com/docs/js/guide#users-facebook-users

Once the user has been identified, the below code logs the user in and forwards them onto a url. This works as expected under Chrome, but will not work using Safari, the page just stays on the fb.html page which is blank

I've seen that there were some historic issues with

window.location.href=

But, can't find a fix that works for my solution. Does anyone know a way around this?

Parse.FacebookUtils.logIn(null, {
    success: function(user) {
        if (!user.existed()) {

        } else {
            window.location.href="user_home.html";

        }
    },
    error: function(user, error) {

    }
});
Dano007
  • 1,872
  • 6
  • 29
  • 63

6 Answers6

17

Best way work in all browsers:

setTimeout(function(){document.location.href = "user_home.html";},250);
stdob--
  • 28,222
  • 5
  • 58
  • 73
  • 1
    Also worth checking is to make sure that Safari isnt blocking popups – Dano007 Jul 04 '15 at 17:33
  • 1
    @Dano007. This worked for me. But what difference does it make setting location.href after a time-out and without timeout ? – kumarmo2 Aug 16 '18 at 06:42
  • 1
    this fix stopped to work for me. i suspect that safari was updated and the fix stopped to work. – Stanislav Jan 10 '19 at 16:58
  • @stanislaw Same here, this fix stopped working recently with me as well. Got a call from a client saying his iphone isn't getting redirects now when using safari. Some people are saying to enable popups but that sort of defeats the purpose, if every one needs to disable that. If any one has come up with a solution I posted a new thread. https://stackoverflow.com/questions/59778280/document-top-location-href-not-working-on-safari-iphone?noredirect=1#comment105701505_59778280 – Brandon Nadeau Jan 18 '20 at 16:56
6

I had this happening to me as well on safari and found this post but found another solution I wanted to add with lots of browser support. Instead of replacing the current location use the method that is on the location object called assign()

document.location.assign(document.location.origin + "/user_home.html")

This also works

location.assign(location.origin + "/user_home.html")

Tested in Chrome and safari on desktop and mobile iOS devices

reference: https://www.w3schools.com/jsref/met_loc_assign.asp

Merb
  • 61
  • 1
  • 4
2

I think you need to use...

window.location = 'user_home.html';
Matthew
  • 639
  • 5
  • 11
0

When I stack to this problem, I made function what working well on any Safari and also all browsers including mobile browsers:

function windowLocation(url){
    var X = setTimeout(function(){
        window.location.replace(url);
        return true;
    },300);

    if( window.location = url ){
        clearTimeout(X);
        return true;
    } else {
        if( window.location.href = url ){
            clearTimeout(X);
            return true;
        }else{
            clearTimeout(X);
            window.location.replace(url);
            return true;
        }
    }
    return false;
};

Is a bit "dirty" solution but give you ability to redirect your page in any case.

Ivijan Stefan Stipić
  • 6,249
  • 6
  • 45
  • 78
0

Probably because you are doing something before it. In other words, the first step in your click event handler must be window.location.href = "https://example.com";.

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91
-1

I wanted to detect home page but faced same problems for iphone and safari.

I simply added a class called "home" in landing page then just check this class as

        if (document.querySelector('.home') !== null) {         
             // the conditions comes here
        }

Details in http://toihid.com/how-to-detect-home-page-in-iphone-and-safari/