我做错了什么? - 我正试图从facebook iframe选项卡中获取用户的区域设置,以根据位置显示相关内容。
<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>
答案 0 :(得分:0)
我对jQuery了解不多,但这里应该有用:
FB.login(function(response) {
if (response.authResponse && response.authResponse.user.locale == "en_GB") {
$("a").attr("href", "URL");
}
});
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();
FB.login(function(response) {
if (response.authResponse && response.authResponse.user.locale == "en_GB") {
$("a").attr("href", "URL");
}
});
}
(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'));
请注意 FB.login 会尝试弹出一个新窗口,因为在此代码中,由于用户操作,该方法未被调用,浏览器可能会阻止弹出窗口。