Skip to content

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
Copy link

tejinderss commented Jul 5, 2013

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

@mattymess
Copy link

mattymess commented Sep 3, 2013

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

@willmorgan
Copy link

willmorgan commented Oct 2, 2013

Thanks for your time in deciphering this.

@glytch
Copy link

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