问题
I'm trying to call a function after a user follows me, and this seems to work just fine on desktop. However on mobile since the popup opens up a new tab rather than a popup window as it does on desktop, its not capturing the callback. Any ideas?
<script>
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));
twttr.ready(
function(twttr) {
twttr.events.bind(
'follow',
function(event) {
var followedUserId = event.data.user_id;
if (followedUserId == "1234567890") {
console.log("Following Twitter account.");
}
}
);
twttr.events.bind(
'unfollow',
function(event) {
var followedUserId = event.data.user_id;
if (followedUserId == "1234567890") {
console.log("Unfollowing Twitter account.");
}
}
);
}
);
</script>
来源:https://stackoverflow.com/questions/31034084/twitter-follow-callback-not-working-on-mobile-safari