我有这个代码,允许用户在我的页面上更新他们的fb状态:
<head>
<title>My Great Website</title>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'**', cookie:true,
status:true, xfbml:true
});
FB.ui({ method: 'feed',
message: 'Facebook for Websites is super-cool'});
</script>
</body>
它工作正常,但是当页面加载时它会自动显示弹出窗口,但我希望该框仅在我按下按钮时显示。这可能吗?我没有在FB文档中看到一个选项。
答案 0 :(得分:2)
demo(“发生了错误。请稍后重试。”正在显示,因为我指定了错误的appID)
<html>
<head>
<title>My Great Website</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'**', cookie:true,
status:true, xfbml:true
});
$(function(){
$("#post-wall").click(function(){
FB.ui({ method: 'feed',
message: 'Facebook for Websites is super-cool'});
return false;
});
});
</script>
<a href="#" id="post-wall">Post feed on your wall</a>
</body>
</html>
答案 1 :(得分:1)
<head>
<title>My Great Website</title>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'**', cookie:true,
status:true, xfbml:true
});
function showMessage() {
FB.ui({ method: 'feed',
message: 'Facebook for Websites is super-cool'});
}
$('.showMessage').click(function() {
showMessage();
});
</script>
<a href="javascript:;" class="showMessage">Show Message</a>
</body>
答案 2 :(得分:1)
<html>
<head>
<title>My Great Website</title>
</head>
<body>
<button onclick="open_fb_dialog()">Open Dialog</button>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'XXXXXX', cookie:true,
status:true, xfbml:true
});
function open_fb_dialog() {
FB.ui({ method: 'feed',
message: 'Facebook for Websites is super-cool'});
}
</script>
</body>
</html>
只需将其放入一个函数中,然后在操作按钮上调用该函数(<button>
,<a>
等等)