[英]Facebook login button event not firing for the first time in IE9
我有一個頁面,我在其中添加了一個自定義的Facebook登錄按鈕,並在該click事件中調用了FB.Login()。
它在除IE9和IE8之外的所有瀏覽器中都能正常工作,問題是當我第一次打開我的網站並單擊登錄按鈕時,沒有彈出窗口出現。 一旦刷新頁面並單擊按鈕,就會彈出窗口。
下面是我的代碼:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId: 'APPID',
status : true,
cookie : true,
xfbml : true,
oauth : true
});
$("#fb").click(function () {
FB.login(function(response) {//calling facebook login
}, {scope: 'user_photos,email,user_birthday,user_likes,user_activities,read_stream,user_religion_politics,user_relationships,user_education_history,user_work_history,user_hometown,user_location'});
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {
//alert("k");
return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<input type="button" class="fb" id="fb" />
我不知道我是否正確,但是我認為最初不會創建Facebook對象,這就是為什么登錄窗口不出現的原因。
你有click
添加到事件#fb
在Facebook上輸入AsyncInit
。 您不確定是否可以在輸入加載后運行。
換句話說,你不能保證執行,你已經結構化的代碼方式的順序,因為click
在回調中添加事件,和DOM(和之前的回調可能被稱為input
元素)已滿載。
嘗試在代碼按鈕之后添加事件。 或者,研究.ready()方法 ,以延遲執行javascript代碼的某些部分,直到DOM完全加載為止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.