如何使用 Javascript/FB.ui 打开和关闭弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6494936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open and close popups with Javascript/FB.ui
提问by Saha
I wrote a simple function to launch a facebook share dialog popup. The problem is, when the user submits the share form the redirect config code in the html link sends the user back to my site withinthe popup, rather than closing the popup and displaying the response fb sends back.
我编写了一个简单的函数来启动 facebook 共享对话框弹出窗口。问题是,当用户提交的份额形式的HTML链接重定向配置代码发送用户返回到我的网站中弹出,而不是关闭弹出窗口并显示响应FB发回。
function popwindow(url)
{
newwindow=window.open(url,'name','height=400,width=700');
if (window.focus) {newwindow.focus()}
}
with the html
与 html
<a href="#" onclick="popwindow('http://www.facebook.com/dialog/feed?app_id=XXX&link=somelink&display=dialog&redirect_uri=http://myurl.net/response/')">Share on Facebook</a>
Now I'm trying to figure out how to get FB's FB.ui js code to work(I'm a js beginner). I've looked through all the similar questions on stackoverflow to no avail. How do I write a link in my page's html to call a FB share dialog that pops up, submits when the user submits it, then closes the popup and sends the user to the proper confirm url with the proper response alerts?
现在我想弄清楚如何让 FB 的 FB.ui js 代码工作(我是一个 js 初学者)。我已经查看了有关 stackoverflow 的所有类似问题,但无济于事。我如何在我的页面的 html 中编写一个链接来调用一个 FB 共享对话框,该对话框弹出,在用户提交时提交,然后关闭弹出窗口并将用户发送到正确的确认 url 并带有正确的响应警报?
I have this default fb code in a facebook.js file
我在 facebook.js 文件中有这个默认的 fb 代码
FB.ui(
{
method: 'feed',
display: 'dialog'
},
function popwindow(url)
{
newwindow=window.open(url,'name','height=400,width=700');
if (window.focus) {newwindow.focus()}
}
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
How do I write out an html link to call the popup and have FB.ui take care of it?
我如何写出一个 html 链接来调用弹出窗口并让 FB.ui 处理它?
回答by Jimmy Sawczuk
You shouldn't have to worry about popping a dialog yourself - the FB.ui
call takes care of that for you. Here's a working example straight from documentationHere's an example with some HTML added:
您不必担心自己弹出对话框 -FB.ui
呼叫会为您处理。这是一个直接来自文档的工作示例这是一个添加了一些 HTML 的示例:
<input type="button" onclick="share_prompt()" value="Share" />
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript" charset="utf-8"></script>
<div id="fb-root"></div>
<script type="text/javascript" charset="utf-8">
FB.init({
appId: 'YOUR_APP_ID',
status: true,
cookie: true,
xfbml: true
});
function share_prompt()
{
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'http://developers.facebook.com/docs/reference/dialogs/',
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.');
}
}
);
}
</script>