我在代码中使用的类似Facebook的按钮无效。我已经做了所有必要的事情:将JavaScript代码放在body标签下面,另一个div
标签放在我希望按钮出现的位置,但是我没有成功。这是我的代码:
<head>
<meta charset="UTF-8" />
<title>Riparian Preserve Survey</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap-responsive.min.css"type="text/css"/>
<link rel="stylesheet" href="bootstrap.css" type="text/css"/>
<script src="jquery-1.9.1.js"></script>
<script src="bootstrap.min.js"></script>
<script src="bootstrap.js"></script>
<style>
img {
max-width: 100%;
}
body{
background-color: #A4A4A4 ;
}
</style>
</head>
<body>
<div id="fb-root"></div>
<script>(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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
...
<div class="fb-like" data-href="https://www.facebook.com/GilbertTownHall"data- send="true" data-width="450" data-show-faces="false"></div>
答案 0 :(得分:1)
Facebook使用SDK我相信首先加载,这是在他们的网站上你试过吗?
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'YOUR_APP_ID', // App ID from the app dashboard
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
};
// 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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
答案 1 :(得分:0)
尝试这样的事情:
window.fbAsyncInit = function () {
if (FB.init) return;
// init the FB JS SDK
FB.init({
appId: 'YOUR_APP_ID', // App ID from the App
//channelUrl: '//' + window.location.hostname + '/channel.html',
//This to get the user details back from Facebook
//scope: 'id,name,gender,user_birthday,email', etc
status: true, // check the login status upon init?
cookie: true, // set sessions cookies to allow your server to access the session?
xfbml: true // parse XFBML tags on this page?
});
}
在HTML Body的末尾......
<script>
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
</script>
你也可以使用fb embeded iframe
Facebook Like Button Reference