我的下面的脚本在Chrome和Firefox上完美运行,但不知何故不适用于IE。代码是检查用户是否是我的页面的粉丝。该脚本既不会重定向到另一个页面(是粉丝)也不会显示likebox(不是粉丝)。
有什么想法吗?我是facebook应用程序和javascript的新手。抱歉我的菜鸟。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Redirecting...please wait</title>
<script type="text/javascript" src="../../src/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../src/js/all.js"></script>
<style type="text/css">
div#container_notlike, div#container_like {
display: none;
}
</style>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : 'APP_ID', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
//if like botton click, reflesh page
FB.Event.subscribe('edge.create',
function(href, widget) {
//alert("Like button clicked");
window.location.reload();
});
FB.getLoginStatus(function(response) {
var page_id = "PAGE_ID";
if (response && response.authResponse) {
var user_id = response.authResponse.userID;
//var accessToken = response.authResponse.accessToken;
var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
FB.Data.query(fql_query).wait(function(rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
console.log("LIKE");
//alert ("Like");
location.href="https://www.example.com/apps";
} else {
console.log("NO LIKEY");
$('#container_notlike').show();
}
});
} else {
FB.login(function(response) {
if (response && response.authResponse) {
var user_id = response.authResponse.userID;
var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
FB.Data.query(fql_query).wait(function(rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
console.log("LIKE");
//alert ("Like");
location.href="https://www.example.com/apps";
} else {
console.log("NO LIKEY");
$('#container_notlike').show();
}
});
} else {
console.log("NO LIKEY");
$('#container_notlike').show();
}
}, {scope: 'user_likes'});
}
});
};
// Load the SDK Asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=APP_ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<center>
<div id="container_notlike">
<fb:like-box href="http://www.facebook.com/example" width="292" height="62" show_faces="false" stream="false" header="false" >
</fb:like-box>
</div>
</div>
</center>
<div id="container_like">
YOU LIKE ME :)
</div>
</body>
</html>
仅供参考:我正在使用IE9并且已经将javascript更新到最新版本。我已经打开了在IE9上运行的JavaScript。
答案 0 :(得分:1)
这是什么?
<script type="text/javascript" src="../../src/js/all.js"></script>
如果是FB SDK,请尝试删除该行。