I was wondering how to do this on page load. It is working with "onClick", i.e <a href="#" onClick="FB.logout()">Logout</a>
<- Works
but if I have something like this done:
// INIT (file 1)
$ ->
$('body').prepend('<div id="fb-root"></div>')
$.ajax
url: "#{window.location.protocol}//connect.facebook.net/en_US/all.js"
dataType: 'script'
cache: true
window.fbAsyncInit = ->
FB.init(appId: 'xxxxxxxxxxxx', cookie: true)
$('#facebook_sign_in').click (e) ->
e.preventDefault()
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
// FILE 2
<script src="file1.js" type="text/javascript"></script>
$(document).ready(function(){
FB.logout(); <- Nothing happens
});
Debugger says, that FB variable is not defined. But why on earth it would be undefined, if onClick works like a charm ?
So, is it somehow possible ?