Facebook的Javascript SDK有一个名为getLoginStatus的方法,当页面上的图像请求停滞(即浏览器长时间未收到200或404响应)时,该方法也会停止(并且不会触发传递给它的回调函数)。如果您等待了非常长的时间,直到浏览器最终关闭尝试获取图像的操作,SDK才会继续正常运行。可能正在发生什么,并且有没有办法防止它?当用户由于图像请求而无法登录或注册时,这非常不方便。请注意保留HTML标记。
阻塞(HTML):
<img src="..." />
非阻塞式(使用CSS):
#someDiv {
background-image: url(...) no-repeat;
width: xxx;
height: xxx;
}
非阻塞式(使用JS):
var img = new Image();
img.onload = function () {
document.getElementById('someDiv').appendChild(img);
};
img.src = "...";
<html>
<head>
<title>This is a test</title>
<script src="http://connect.facebook.net/fr_FR/sdk.js"></script>
<script language="javascript">
<!--
var loggedIn = false;
var authenticated = false;
FB.init({
appId : '{your app ID here}',
xfbml : true,
version : 'v2.0'
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated 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;
loggedIn = true;
authenticated = true;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
loggedIn = true;
} else {
// the user isn't logged in to Facebook.
}
});
function testLogin()
{
alert("Logged in: " + loggedIn + "\nAuthenticated: " + authenticated);
}
// -->
</script>
</head>
<body>
Testing!
<button onclick="testLogin()">Test login?</button>
<img src="http://deelay.me/5000/ http://example.com/image.gif">
</body>
</html>
你有安装任何广告拦截器吗?我曾经遇到过类似的问题,使用 Adblock Pro 会导致一些问题。
getLoginStatus
方法。 - John O'Neill