Instantly share code, notes, and snippets.

Embed
What would you like to do?
proper twitter callback
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
var url = "https://twitter.com/intent/tweet?" + $.param({
url: "http://www.google.com",
text: "text"
});
$(window).bind("message", function(event) {
event = event.originalEvent
if(event.source == share_window && event.data != "__ready__") {
console.log($.parseJSON(event.data));
}
});
var share_window = window.open(url);
});
</script>
</body>
</html>
@tejinderss

This comment has been minimized.

tejinderss commented Jul 5, 2013

define share_window at the start of script, otherwise I get an error that share_window is undefined.

@mattymess

This comment has been minimized.

mattymess commented Sep 3, 2013

Thanks so much for this. You saved me a ton of headache!

@willmorgan

This comment has been minimized.

willmorgan commented Oct 2, 2013

Thanks for your time in deciphering this.

@glytch

This comment has been minimized.

glytch commented Dec 3, 2014

I looked all over the internet for this. thanks.

I'm going to include some stuff that would have helped me find this page via search. twttr event bind intent callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment