Facebook Authentication - Unsafe JavaScript attempt to access frame with URL

后端 未结 7 1162
别那么骄傲
别那么骄傲 2021-01-11 20:14

I am trying to implement Facebook Login System into my website.

While it try to connect to facebook, I get an error from console log:

Unsafe JavaScri         


        
相关标签:
7条回答
  • 2021-01-11 20:29

    You can tweak your localhost machine to appear to be of the domain that facebook requires.

    On linux or OSX, add an entry to /etc/hosts; on windows, edit c:\windows\system32\drivers\etc\hosts. Add an entry like this:

    127.0.0.1 local-dev.mydomain.com local-dev
    

    Where "mydomain.com" is the domain with which your FB app ID is registered.

    0 讨论(0)
  • 2021-01-11 20:32

    Be sure to have this line on the top of your page (it works for me) :

    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="https://www.facebook.com/2008/fbml">
    
    0 讨论(0)
  • 2021-01-11 20:36

    It is not possible to test all Facebook integration using domain localhost. You need to place your script in any public access domain and need to update the url in developer app settings page. The security error showing from JavaScript is due to this localhost access by facebook scripts

    0 讨论(0)
  • 2021-01-11 20:37

    Had this error when I implemented fileglu and it may be a CORS error since you are running off localhost. Try running on Facebook and can you replace the bottom half with the code below:

    (function() {
      var e = document.createElement('script');
      e.src = document.location.protocol + 
         '//connect.facebook.net/en_US/all.js#appId=<your-app-id>&xfbml=1';
      e.async = true;
      document.getElementById('fb-root').appendChild(e);
    }());
    

    I also had Oauth 2.0 and custom channel enabled in my FB.init() page. See: http://fbdevwiki.com/wiki/FB.init for more information.

    0 讨论(0)
  • 2021-01-11 20:40

    You can only use the same domain name in which you have registered with Facebook apps.

    1. You need a public domain name (www.example.com).
    2. You need to register with Facebook apps.
    3. Get the 2 keys from the Facebook and use in the code:
    
        appId      : 'xxxxxxxxxxxxxx',
    
    0 讨论(0)
  • 2021-01-11 20:45

    The error that you see there is a non-fatal error. There is no workaround for this, as your browser is advising you that it is not a great idea to load JavaScript from foreign domains. Just ignore this message and look elsewhere for bugs if your scripts do not run. Sajith is also correct that you can't debug from localhost.

    See here also, "Unsafe JavaScript attempt to access frame with URL..." error being continuously generated in Chrome webkit inspector

    0 讨论(0)
提交回复
热议问题