尝试使用Facebook JavaScript SDK实现Facebook连接时出现以下错误: -
未捕获的DOMException:使用origin阻止了一个帧 " https://staticxx.facebook.com"从访问跨源框架。 在ga(https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:48:2439) at Object.ba [as send](https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:48:2533) at Object.aa [as whenReady](https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:50:2987) 在Object.x [as init](https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:48:3091) at Object.w [as create](https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:48:963) 在https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:50:2447 在(https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:50:3023) at require(https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:31:585) 在https://staticxx.facebook.com/connect/xd_arbiter/r/fTmIQU3LxvB.js?version=42:50:3146
我使用以下代码: -
window.fbAsyncInit = function() {
FB.init({ appId: fbAppId,
status: true,
cookie: true,
xfbml: true,
oauth: true
});
function updateButton(response) {
button = document.getElementById('fb-auth');
if (response.authResponse) {
//user is already logged in and connected
FB.api('/me', function(info) {
login(response, info, calFrom,fbAppId);
});
} else {
//user is not connected to your app or logged out
button.onclick = function() {
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(info) {
login(response, info, calFrom,fbAppId);
});
} else {
//user cancelled login or did not grant authorization
}
}, { scope: 'publish_actions,manage_pages' });
}
}
}
// run once with current status and whenever the status changes
FB.getLoginStatus(updateButton);
FB.Event.subscribe('auth.statusChange', updateButton);
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());