简体   繁体   English

在IE9中首次未触发Facebook登录按钮事件

[英]Facebook login button event not firing for the first time in IE9

I have a page in which i have added a customised facebook login button and im calling FB.Login() inside that click event. 我有一个页面,我在其中添加了一个自定义的Facebook登录按钮,并在该click事件中调用了FB.Login()。

It works fine in all browser except IE9 and IE8 , the problem is when for the first time i open my site and click on login button no pop up window comes. 它在除IE9和IE8之外的所有浏览器中都能正常工作,问题是当我第一次打开我的网站并单击登录按钮时,没有弹出窗口出现。 Once i refresh my page and click on button the pop up window occurs. 一旦刷新页面并单击按钮,就会弹出窗口。

Below is my code: 下面是我的代码:

<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" />

I dont know if i'm correct or not, but i think initially that facebook object is not getting created thats why login window is not coming. 我不知道我是否正确,但是我认为最初不会创建Facebook对象,这就是为什么登录窗口不出现的原因。

You have the click event being added to the #fb input on the Facebook AsyncInit . 你有click添加到事件#fb在Facebook上输入AsyncInit You cannot know for certain that this will run after the input has loaded. 您不确定是否可以在输入加载后运行。

In other words, you cannot guarantee the order of execution, the way you have structured the code, because the click event is added on a callback, and that callback can possibly be called before the DOM (and the input element) has fully loaded. 换句话说,你不能保证执行,你已经结构化的代码方式的顺序,因为click在回调中添加事件,和DOM(和之前的回调可能被称为input元素)已满载。

Try adding the event after the button for the code. 尝试在代码按钮之后添加事件。 Alternatively, investigate the .ready() method , to delay some portions of javascript code from executing until the DOM has fully loaded. 或者,研究.ready()方法 ,以延迟执行javascript代码的某些部分,直到DOM完全加载为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM