Loading the Facebook API in JSFiddle

点点圈 提交于 2019-12-11 01:25:55

问题


I want to be able to load the Facebook API inside JSFiddle. This is my current attempt.

When I run:

window.fbAsyncInit = function() {
  FB.init({
    appId: 'event-test',
    xfbml: true,
    version: 'v2.5'
  });
};

I get the following error:

Uncaught SecurityError: Failed to set the 'domain' property on 'Document': Assignment is forbidden for sandboxed iframes.(anonymous function) @ xd_arbiter.php?version=42:1

Is there any way I can get this working?


回答1:


I don't know much about the Facebook login API. However, I do understand why you are getting the error message.

If you were to put your code inside a file on your computer's hard drive without jsfiddle, it should work.

Short answer: There is no way to get this to work with your current setup on jsfiddle. You can try looking for an alternative Facebook API if Facebook has a different API available that does the same thing.

Long answer: Sandbox is an attribute that be assigned to the iframe tag for security measures for the parent page. JsFiddle uses sandbox to provide security to the parent page. Your fiddle results are loaded into an iframe that looks like this:

<iframe name="result" sandbox="allow-forms allow-popups allow-scripts allow-same-origin allow-modals" frameborder="0" src="//fiddle.jshell.net/casebash/j26bq6qf/11/show/"></iframe>

Facebook just doesn't want their API to run within a Sandboxed iframe.



来源:https://stackoverflow.com/questions/34426959/loading-the-facebook-api-in-jsfiddle

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