当用户在我的Facebook应用程序上单击链接时,我该如何显示一个典型的Facebook模态帮助对话框?
谢谢。
// First, define the HTML content you want in the dialog as a javascript string:
var content = '<div><h2>Help is here!</h2><div>Hint: you can eat the cookies!</div></div>';
// Then add the content to this resource dictionary thing, wrapped in a div with the id "RES_ID[your identifier here]"
FB.UI.DomResources.addResourceDict(new FB.UI.DomResDict('<div id="RES_IDhelp01">' + content + '</div>'));
// Instantiate the popup dialog and show it:
var popup = new FB.UI.PopupDialog('Help?!', FB.UI.DomResources.getResourceById('help01'), false, false);
popup.show();
Codebliss的链接引导我进入了一个文档页面,向我展示如何使用他们的JS SDK在网页中调用iframe弹出对话框。首先,您必须加载Facebook脚本:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: '[YOUR_APP_ID]', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
然后在你的页面中放置类似于以下内容:
<a href="#" id="test">click me</a>
// some code
$(document).ready(function() {
$('#test').click(function() {
FB.ui({
method: 'feed',
name: 'Facebook Dialogs',
link: '[YOUR_WEBSITES_REGISTERED_URL_ON_FB]',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.',
message: 'Facebook Dialogs are easy!'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
});
});
});