admin管理员组文章数量:1302921
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 within the popup, rather than closing the popup and displaying the response fb sends back.
function popwindow(url)
{
newwindow=window.open(url,'name','height=400,width=700');
if (window.focus) {newwindow.focus()}
}
with the html
<a href="#" onclick="popwindow(';link=somelink&display=dialog&redirect_uri=/')">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?
I have this default fb code in a facebook.js file
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?
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 within the popup, rather than closing the popup and displaying the response fb sends back.
function popwindow(url)
{
newwindow=window.open(url,'name','height=400,width=700');
if (window.focus) {newwindow.focus()}
}
with the html
<a href="#" onclick="popwindow('http://www.facebook./dialog/feed?app_id=XXX&link=somelink&display=dialog&redirect_uri=http://myurl/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?
I have this default fb code in a facebook.js file
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?
Share Improve this question edited Jun 27, 2011 at 15:43 Saha asked Jun 27, 2011 at 15:05 SahaSaha 31 gold badge1 silver badge3 bronze badges 2- window.focus is not a boolean, its a function, so it will always evaluate as true – Ibu Commented Jun 27, 2011 at 15:46
- what you need to do is look at the facebook dev documentation – Ibu Commented Jun 27, 2011 at 15:47
1 Answer
Reset to default 6You 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 documentation Here's an example with some HTML added:
<input type="button" onclick="share_prompt()" value="Share" />
<script src="http://connect.facebook/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./docs/reference/dialogs/',
picture: 'http://fbrell./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>
本文标签: facebookHow to open and close popups with JavascriptFBuiStack Overflow
版权声明:本文标题:facebook - How to open and close popups with JavascriptFB.ui - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741743200a2395377.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论