Show FB status update popup on click?
I have this code which allows the user to u开发者_如何学编程pdate their fb status on my page:
<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>
It works fine but when the page loads it automatically shows the popup, but I want the box to only show when I press a button. Is this possible? I don't see an option in the FB Documentation.
demo ("An error occurred. Please try again later." is showing because I have wrong appID specified)
<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>
<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>
<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>
Just put it inside a function and call the function on your action button (<button>
, <a>
..etc)
精彩评论