Facebook的Javascript SDK有一个名为getLoginStatus
的方法,当页面上的图像请求也停止时(即浏览器没有收到200或404)很长一段时间。)
如果您等待极其很长时间并且浏览器(?)最终关闭了获取图像的尝试,那么SDK会继续以愉快的方式继续。
可能会发生什么,有没有办法阻止它?当用户因图像请求无法登录或注册时,这非常不方便。
答案 0 :(得分:2)
阻止(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 = "...";
尝试使用解决方案2或3 - JavaScripts还有许多预加载器插件,可以更轻松地异步加载大量图像,例如:http://thinkpixellab.com/pxloader/
另一个解决方案是首先加载较小的图像并异步加载雇用的图像。
答案 1 :(得分:1)
当您使用Facebook SDK网站上的初始化代码时,默认情况下,它希望等待页面完全加载以运行某些事件,例如fbAsyncInit函数。
我不确定是否采用“官方支持”的方法来绕过这个,但您可以自己加载Javascript源并直接调用例程(即不在异步包装器中)。
这是一个准确的例子,就像你提到的使用Facebook SDK初始化程序一样停滞不前,但这种解决方法可以正常工作。
<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>
我不确定这会如何影响与您网站的集成,但我无法想象这会是一个问题。如果有什么我认为值得一试!
答案 2 :(得分:0)
您是否设置了广告拦截器?我在使用不同的API时遇到了类似的问题,Adblock Pro导致了一些问题。