Facebook FB.Init Refused to display in a frame because it set 'X-Frame-Options' to 'DENY'

北城以北 提交于 2019-12-02 05:55:41

问题


Following the Facebook instructions, FB.Init in Chrome produces

Refused to display 'https://www.facebook.com/connect/ping?...' in a frame because it set 'X-Frame-Options' to 'DENY'.

However, there are no frames on the page. IE, strangely enough, seems happy with the call.

Based on a stackoverflow suggestion, I added

<httpProtocol>
    <customHeaders>
      <add name="X-Frame-Options" value="SAMEORIGIN" />
    </customHeaders>
</httpProtocol> 

to system.webServer

to no avail.

So something else is happening here. There seems to be a lot questions on SO relating to this problem, but with no clear solution.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>hello world</h1>

<script>
    // -----------------------------
    var FBinitialised = false;

     window.fbAsyncInit = function() {
        FB.init({
            appId      : '<MY_APP_ID>',
            cookie     : true,
            xfbml      : true, 
            version    : 'v2.8'
        });

        console.log( 'after FB.init');

        FB.getLoginStatus( function( response){
            FBinitialised = true;
            console.log( 'FBinitialised');
        });
    };

    // ---------------------------------
    // 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/sdk.js';
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

    console.log( 'End of script');

</script>
</body>
</html>

Anyone know what is going on?


回答1:


After much boredom, it appears that Chrome and FF on my machine have been corrupted, perhaps by Kaspersky script injection. Re-installing W10 has solved the problem. Apologies.



来源:https://stackoverflow.com/questions/41939363/facebook-fb-init-refused-to-display-in-a-frame-because-it-set-x-frame-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!