Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Intent Callback Events via Window.open Just Not Happening

Wonder if anyone can help. See attached code below:

  • If I launch a Web Intent via a normal "a href", and then tweet I get the callback. Lovely.

  • If, however, I launch a Web Intent via a window.open, say from a button click, I don't. See code below.

  • I could, trap the button click, and then call click on the "a href". At this point, I do then get the callback. However, this action in some browsers (e.g. Safari) gets caught in the pop-up blocker, so no-one sees the popup. Which is a bit useless.

I would like to use the window.open approach, and get the callback. Any thoughts anyone?

<!doctype html>
<html lang="en">
<head lang=en>
    <meta charset="utf-8">
    <title>Web Intent t3 Experiment</title>
    <script src="http://d3js.org/d3.v3.min.js"></script>
    <script src="https://platform.twitter.com/widgets.js" type="text/javascript">    </script>
</head>
<body>

<a href="https://twitter.com/intent/tweet?url=http://www.google.com&text=testing web intents">Option 1: Tweet via Link</a><br />
<button id="tf_sendtweet_button">Option 2: Tweet Via Button and JS</button>

<script type="text/javascript">
var t_element = d3.select("#tf_sendtweet_button");
t_element.on("click", function() {
        _text = "Some compelling text to go in a tweet";
        _url = "http://www.google.com/";

        var tweet_url = 'https://twitter.com/intent/tweet?text=';
        tweet_url += encodeURIComponent(_text);
        tweet_url += '&url=' + encodeURIComponent(_url);
        window.open(tweet_url,'_blank');
});



// Here, trap the callback from the WebIntent.
twttr.ready(function (twttr) {
    // bind events here
    twttr.events.bind('tweet', function (event) {
        alert("Yay, tweet callback baby. Gotcha.");
        console.log(new Date(), "Sweett, tweet callback: ", event);
    });
}); 
</script>
</body>
</html>
like image 303
Roland Dunn Avatar asked Feb 03 '26 20:02

Roland Dunn


1 Answers

Ok, everyone stand easy. It's been answered by a Twitter employee:

Unfortunately you can’t use the callback events features without letting our javascript control the window opening.

https://twittercommunity.com/t/get-web-intent-callback-from-a-window-open-call/20881

like image 172
Roland Dunn Avatar answered Feb 05 '26 13:02

Roland Dunn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!