Nick
Nick

Reputation: 315

Facebook JavaScript not working on IE, but working on Firefox and Chrome

My script below works perfectly on Chrome and Firefox but somehow doesn't work on IE. The code is to check whether the user is a fan of my page yet or not. The script neither redirect to another page (is a fan) nor show the likebox (not a fan).

Any idea? I'm very new to facebook application and javascript. Sorry for my noob.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Redirecting...please wait</title>

<script type="text/javascript" src="../../src/js/jquery-1.7.1.min.js"></script>  
<script type="text/javascript" src="../../src/js/all.js"></script>  
<style type="text/css">
  div#container_notlike, div#container_like {
    display: none;
  }
</style>

</head>

<body>

<div id="fb-root"></div>
<script type="text/javascript">
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'APP_ID', // App ID
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    //if like botton click, reflesh page
    FB.Event.subscribe('edge.create', 
        function(href, widget) {
        //alert("Like button clicked");
        window.location.reload();
    });

    FB.getLoginStatus(function(response) {
      var page_id = "PAGE_ID";
      if (response && response.authResponse) {
        var user_id = response.authResponse.userID;
        //var accessToken = response.authResponse.accessToken;
        var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
        FB.Data.query(fql_query).wait(function(rows) {
          if (rows.length == 1 && rows[0].uid == user_id) {
            console.log("LIKE");
            //alert ("Like");
            location.href="https://www.example.com/apps";


          } else {
            console.log("NO LIKEY");
            $('#container_notlike').show();

          }
        });
      } else {
        FB.login(function(response) {
          if (response && response.authResponse) {
            var user_id = response.authResponse.userID;
            var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
            FB.Data.query(fql_query).wait(function(rows) {
              if (rows.length == 1 && rows[0].uid == user_id) {
                console.log("LIKE");
                //alert ("Like");
                location.href="https://www.example.com/apps";
              } else {
                console.log("NO LIKEY");
                $('#container_notlike').show();

              }
            });
          } else {
            console.log("NO LIKEY");
            $('#container_notlike').show();

          }
        }, {scope: 'user_likes'});
      }
    });
  };

  // Load the SDK Asynchronously
    (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=APP_ID";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>

<center>
<div id="container_notlike">
          <fb:like-box href="http://www.facebook.com/example" width="292" height="62" show_faces="false" stream="false" header="false" >
          </fb:like-box>

    </div>
</div>
</center>

<div id="container_like">
  YOU LIKE ME :)
</div>

</body>
</html>

FYI: I'm using IE9 and already update javascript to latest version. I've already opened javascript to run on IE9.

Upvotes: 0

Views: 3125

Answers (1)

Bruno
Bruno

Reputation: 1368

What is this?

<script type="text/javascript" src="../../src/js/all.js"></script>  

If it's the FB SDK, try and remove that line.

Upvotes: 1

Related Questions