林其在Facebook上的JavaScript错误“遗漏的类型错误:不能为空的设置属性的‘onClick’”行187和行187:错误遗漏的类型错误:无法设置属性的“onClick”空的
" button.onclick = function() {"
所有的代码是:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({ appId: <?php echo json_encode($this->getApiKey()) ?>,
status: true,
cookie: true,
xfbml: true,
oauth: true});
FB.Canvas.setSize({ width: 640, height:1500 });
//FB.Canvas.setAutoResize();
function updateButton(response) {
var button = document.getElementById('fb-auth');
if (response.authResponse == 'null') {
//user is already logged in and connected
var userInfo = document.getElementById('user-info');
FB.api('/me', function(response) {
});
button.onclick = function() {
FB.logout(function(response) {
var userInfo = document.getElementById('user-info');
userInfo.innerHTML="";
});
};
} else {
//user is not connected to your app or logged out
//button.innerHTML = 'Login';
button.onclick = function() {
FB.login(function(response) {
if(response.status=='connected') setLocation('<?php echo $this->getConnectUrl() ?>');
if (response.authResponse) {
FB.api('/me', function(response) {
var userInfo = document.getElementById('user-info');
});
} else {
//user cancelled login or did not grant authorization
}
}, {scope:'email, user_birthday'});
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
//FB.Event.subscribe('auth.statusChange', updateButton);
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol
+ '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
如果需要更多的信息,只是告诉我 我欣赏的帮助。 谢谢!
它说'按钮现在:null'。 –
你是否过早调用updateButton函数?看起来没有ID为“fb-auth”的元素,所以你不能添加一个onclick事件。你的代码不会在fbAsyncInit被调用时显示,但是我的猜测是当内容尚未加载或者你期望的内容不存在时调用它。 – HMR
对,没有呼叫fb-auth我只是改变了呼叫.. 但仍然是相同的..该电话是一个HTML不显示在网络上,我的意思是没有人会去那里.. –