How to redirect based on FB Login Status in all modern mobile and desktop browsers?

Jeff P.
Jeff P. used Ask the Experts™
on
My company redirects a user based on if they are logged into Facebook or not. But we are having cross browser issues and I need another set of eyes.

Firefox blocks the connection to Facebook if tracking protection is on, not sure if I can get around that. I just need a popup to open even if login status fails. I tried a delayed meta refresh and that didn't even work.

<script>
	  window.fbAsyncInit = function() {
	    FB.init({appId: '' . $fb_app_id . '', status: true, cookie: true, xfbml: true});
	    FB.getLoginStatus(function(f) {
		if (!f && f.status) return;
		       if (f.status == 'connected') {
				var url = "http://google.com";
				url = new URL(url);
				window.open(url, "_self");
		        } else if (f.status == 'not_authorized') {
				var url = "http://google.com";
				url = new URL(url);
				window.open(url, "_self");
		       } else {
				var url = "http://gmail.com";
				url = new URL(url);
				window.open(url, "_self");
		       }
		});
	  };
	  (function() {
	    var e = document.createElement('script'); e.async = true;
	    e.src = document.location.protocol +
	      '//connect.facebook.net/en_US/all.js';
	    document.getElementById('fb-root').appendChild(e);
	  }());
</script>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
LAMP Dev
Commented:
The issue was FB.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial