title: Facebook javascript SDK FB.login is not working in Facebook iFrame
body: <p>We are using Facebook JavaScript SDK to authenticate our Facebook application. The application is configured with the Canvas URL as <a href="http://facebook.elgifto.com/Home/Index/" rel="noreferrer">http://facebook.elgifto.com/Home/Index/</a>. Following is the code we are using to authenticate the Facebook user.</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
            window.fbAsyncInit = function() {
                debugger;
                    FB.init({
                        appId: '&lt;%= ViewData["AppId"].ToString() %&gt;', // App ID
                        channelUrl: '&lt;%= ViewData["ChannelUrl"].ToString() %&gt;', // Channel File
                        status: true, // check login status          
                        cookie: true, // enable cookies to allow the server to access the session
                        xfbml: true,  // parse XFBML
                        oauth: true
                    });
  
                FB.Event.subscribe('auth.login', function(response) {
                    if (response.status === 'connected') {
                        // the user is logged in and connected to your
                        // app, and response.authResponse supplies
                        // the user’s ID, a valid access token, a signed
                        // request, and the time the access token 
                        // and signed request each expire
                        var uid = response.authResponse.userID;
                        var accessToken = response.authResponse.accessToken;
                        startApp(uid, accessToken);
                    }
  
                });
  
            };
  
            // Load the SDK Asynchronously
            (function(d) {    
                var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { 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));
  
  
  
  
            function startApp(uid, accessToken) {                 
                var baseUrl = '&lt;%= ViewData["AppBaseURL"].ToString() %&gt;';
                var redirectUrl = baseUrl + '?uid=' + uid + '&amp;accessToken=' + accessToken;
                window.top.location.href = redirectUrl;
                //document.location = redirectUrl;
            }          
         &lt;/script&gt;
  &lt;fb:login-button onlogin="initiateLogin()" perms="email,user_about_me,user_birthday,friends_about_me,friends_birthday"&gt;Login with Facebook&lt;/fb:login-button&gt;
  </code></pre>
  
  <p>The above code is not working in the Facebook when accessed as <a href="http://apps.facebook.com/giftguru" rel="noreferrer">http://apps.facebook.com/giftguru</a>. However we are able to access it through <a href="http://facebook.elgifto.com/Home/Index" rel="noreferrer">http://facebook.elgifto.com/Home/Index</a></p>