Facebook SDK window.fbAsyncInit没有在localhost上触发?上周工作正常。
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
console.log("hey");
// init the FB JS SDK
FB.init({
appId : '***************', // App ID from the App Dashboard
channelUrl : '//localhost/channel.html', // Channel File
status : true, // check the login status upon init?
cookie : true, // set sessions
xfbml : true // parse XFBML tags on this page?
});
}
// Load the SDK's source Asynchronously
// Note that the debug version is being actively developed and might
// contain some type checks that are overly strict.
// Please report such bugs using the bugs tool.
(function(d, debug){
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" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ true));
</script>
“hey”在加载页面时不会触发
另外我注意到当我在“Fb.init”中注释掉频道网址时,却添加了:
<script src="//connect.facebook.net/en_US/all.js"></script>
在文件的标题内,“嘿”会在首次加载页面时触发,但不会在后续尝试时触发
更明确。这就是我的控制台中的错误:
Uncaught SyntaxError: Unexpected token ( connect.facebook.net/en_US/all/debug.js:9237
答案 0 :(得分:0)
您错过了加载FB.init()下面的SDK。
(function(d, debug){
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" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));`
https://developers.facebook.com/docs/reference/javascript/
并确保在App setting page中设置App Domains
。
答案 1 :(得分:0)
目前在all.js的调试版本的呈现中存在一个错误 - 导致您的代码无法正确执行。这将很快得到解决。