I have a localhost
website and script with FB.logout()
. After some actions, it fails to log me out and I see next error message in console:
Refused to display 'https://www.facebook.com/home.php' in a frame because it set 'X-Frame- Options' to 'DENY'.
I searched all StackOverflow and didn't find any working solution. Network inspector shows cancelled near home.php query.
So I understand that the script tries to load the Facebook homepage in a frame, but it can't because it is prohibited. So how can I fix it? Why doesn't logout()
work for me?
My code
// Facebook Basic Example window.fbAsyncInit = function() { FB.init({ appId : '579651098766258', status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true // parse XFBML }); FB.Event.subscribe('auth.authResponseChange', function(response) { if (response.status === 'connected') { testAPI(); } else if (response.status === 'not_authorized') { FB.login(); } else { FB.login(); } }); }; (function(d){ var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; ref.parentNode.insertBefore(js, ref); }(document)); function testAPI() { FB.api('/me', function(res) { console.log(res); setTimeout(function(){ FB.logout(); // <-- ERROR }, 2000); }); }
This solution worked for me:
Also I made a youtube video to solve this problem: https://www.youtube.com/watch?v=7CNpLgwa0-c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With