What am I doing wrong? – I’m trying to grab the user’s locale from a facebook iframe tab to display relevant content based on location.
<script type="text/javascript">
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=" + 'MY APP ID';
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function () {
if (location.protocol == 'https:') {
FB._https = true;
};
FB.init({
appId: 'MY APP ID',
status : false,
cookie : false,
xfbml : true,
width: 810
});
FB.Canvas.scrollTo(0,0);
FB.Canvas.setAutoGrow();
}
</script>
<script>
FB.login(function(response) {
if (response.authResponse) {
if ($.data.get('user').get('locale') = "en_GB") {
$("a").attr("href", "URL");
}
}
});
</script>
I don’t know much about jQuery, but here’s something that should work:
Edit
Oh yeah.
The loading of the fb sdk is asynced, and so you need to use the FB namespace only after the fbAsyncInit method was called.
Try this:
Just be aware that FB.login tries to popup a new window and since in this code the method is not being called due to a user action, the browser will probably block the popup.