抓住Facebook的意见箱关闭或发贴到Facebook活动 [英] Catching the close or post to Facebook event of the Facebook comment box

查看:234
本文介绍了抓住Facebook的意见箱关闭或发贴到Facebook活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用Facebook他们的XFBML解决方案在我的页面上显示类似的按钮。 / p>

使用JavaScript我设法捕获按下相似按钮时触发的事件,但现在我需要一种方法来检测用户是否按下发布到Facebook按钮或关闭对话框。



以下代码片段适用于类似的按钮事件:

 (function(d,s,id){
var js,fjs = d.getElementsByTagName(s)[0];
if(d.getElementById(id) return;
js = d.createElement(s); js.id = id;
js.src =//connect.facebook.net/en_US/all.js#xfbml=1&appId= 1427863577435532;
fjs.parentNode.insertBefore(js,fjs);
}(document,'script','facebook-jssdk'));


window.fbAsyncInit = function(){
FB.init({
status:true,
cookie:true,
xfbml :true
});

FB.XFBML.parse();

FB.Event.subscribe('edge.create',function(href){
console.log(edge.create);
});
}

我用于显示该按钮的代码是:

 < fb:like href =https://developers.facebook.com/docs/plugins/layout =box_countaction =像show_faces =falseshare =false>< / fb:like> 

我试图抓住关闭或发贴到Facebook事件,以下解决方案(在FaceBook和 https://stackoverflow.com/ 上找到),没有任何成功。

  FB.Event.subscribe('comment.add',function(resp){
console.log(comment.add);
} );

FB.Event.subscribe('comments.add',function(resp){
console.log(comments.add);
});

FB.Event.subscribe('comments.create',function(resp){
console.log(comments.create);
});

FB.Event.subscribe('comment.create',function(resp){
console.log(comment.create);
})

我需要做的最终解决方案是:


  1. 将数据存储到数据库中时,可以将数据存入数据库[管理解决此问题]

  2. 当用户完成与对话框的交互时,重新加载页面(当对话框为关闭或发布到FaceBook按钮被按下)

任何人有一个好主意或提示来解决这个问题或推动我走向正确的方向

解决方案

我通过使用jQuery查看Facebook弹出窗口的高度来解决问题,然后在定义的时间间隔内查看定时器查看弹出窗口是否仍然具有相同的宽度(当弹出窗口关闭/隐藏时,宽度更改)。



使用jQuery获取Facebook的iframe,如按钮。最简单的方法是将类似按钮包装在div中。一旦将iframe放在一个名为fb_like_iframe的变量中。



接下来使用以下代码:

  var pollTimerFB = window.setInterval(function(){
var fb_iframe_height = jQuery(fb_like_iframe).height();
if(fb_iframe_height< 100){
window.clearInterval(pollTimerFB);
//当FaceBook弹出窗口关闭时需要执行的代码
//来到这里
}
},1000);

该代码将检查每一秒的FaceBook弹出窗口是否关闭,如果不是会停留在循环中。如果它是关闭的,它会执行您希望执行的代码,然后停止循环。



使用此代码将其放入

  FB.Event.subscribe('edge.create',function(href){
//代码获取iFrame
//代码(从上方)到窗口打开时轮询
});

使用上述方法将会在每次用户按下FaceBook的按钮时启动轮询机制。 p>

希望Facebook会在弹出窗口关闭时立即添加一些事件。


The new Facebook like button has a comment box, as you can see on the screenshot below.

I am using Facebook their XFBML solution to display the like button on my page.

Using JavaScript I manages to catch the event that is triggered when the like button is pressed but now I need a way to detect if the user pressed the "Post to Facebook" button or closed the dialog box.

Here is the code snippet that works for the like button event:

(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=1427863577435532";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


window.fbAsyncInit = function() {
    FB.init({
        status: true,
        cookie: true,
        xfbml: true
    });

    FB.XFBML.parse();

        FB.Event.subscribe('edge.create', function(href) {
        console.log("edge.create");
    });
}

The code that I use to display the button is:

<fb:like href="https://developers.facebook.com/docs/plugins/" layout="box_count" action="like" show_faces="false" share="false"></fb:like>

I've tried to catch the "close" or "Post To Facebook" event with any of the following solutions (found on FaceBook and https://stackoverflow.com/) without any successes.

FB.Event.subscribe('comment.add', function(resp) {
    console.log("comment.add");
});

FB.Event.subscribe('comments.add', function(resp) {
    console.log("comments.add");
});

FB.Event.subscribe('comments.create', function(resp) {
    console.log("comments.create");
});

FB.Event.subscribe('comment.create', function(resp) {
    console.log("comment.create");
})

The end solution that I need to make is:

  1. Store data into the database when a like is done [managed to solve this]
  2. Reload the page when user is done interacting with the dialog box (when dialog is closed or post to FaceBook button is pressed)

Anyone with a good idea or tip to solve this issue or push me into the right direction?

解决方案

I solved it by looking at the height of the Facebook popup using jQuery and then have a timer looking in defined time intervals to see if the popup was still having the same width (width changes when the popup is closed/hidden).

Use jQuery to get the iframe of Facebook like button. The easiest to do this is to wrap the like button in a div. Once you have the iframe put it in a variable called fb_like_iframe.

Next use the following code:

var pollTimerFB = window.setInterval(function() {
    var fb_iframe_height = jQuery(fb_like_iframe).height(); 
    if (fb_iframe_height < 100) {
        window.clearInterval(pollTimerFB);
        // Code that needs to be executed when the FaceBook popup is closed
        // comes here
    }
}, 1000);

The code will check every second of the FaceBook popup is closed, if not it will stay in the loop. If it is closed it executes the code you want it to execute and then stops looping.

The best way to use this code to put it inside the

FB.Event.subscribe('edge.create', function(href) {
    // Code to get iFrame
    // Code (from above) to poll if window is open
});

Using the above method will start the polling mechanism each time a user presses the FaceBook like button.

Hopefully Facebook will add some event soon that can be used for when the popup is closed.

这篇关于抓住Facebook的意见箱关闭或发贴到Facebook活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆