After successful tweet, execute the callback + Twitter

后端 未结 1 731
别跟我提以往
别跟我提以往 2020-12-20 00:27

I am doing the \"share on Twitter\" functionality. I have share button and when I click it will open a widget of twitter and showing me the share box. When I will press on T

相关标签:
1条回答
  • 2020-12-20 01:15

    Generally there is no method or intent for a callback from a tweet. I used below hack to make a callback after a successful tweet:

    window.twttr = (function (d,s,id) {
        var t, js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
        js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
        return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
        }(document, "script", "twitter-wjs"));
    
    $(document).on('click','.twitter',function(){
    
       var tweetUrl = 'https://twitter.com/intent/tweet?url='+window.location.href;
       var x = screen.width/2 - 700/2;
        var y = screen.height/2 - 450/2;
        var child = window.open(tweetUrl, "popupWindow", "width=600, height=400,left="+x+",top="+y);
           child.focus();
          var timer = setInterval(checkChild, 1);
          document.domain = 'example.com';     //Replace it with your domain
          function checkChild() {
            if(child.closed){
              clearInterval(timer);
            }
            if(child.window && child.window.closed){   //Code in this condition will execute after successfull post
              //Do your stuff here
              console.log('I am here after a successful tweet.');
              clearInterval(timer);
            }  
          }
    });
    
    <a class="twitter"  href="javascript:void(0)">Tweet</a>
    
    0 讨论(0)
提交回复
热议问题