Unable to fire Twitter Click event
I want to call jcl callback js function on "Tweet". My code:
<a href="https://twitter.com/share" class="twitter-share-button" data-url="https://twitter.com/share" data-via="josephjohnbless">Tweet</a>
<script>
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 = "https://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"));
</script>
<script>
twttr.ready(function (twttr) {
twttr.events.bind('click', function (event) { alert('yes'); });
});
</script>
There is Uncaught TypeError: Cannot read property 'ready' of undefined
for twttr.ready()
. I saw that this is a valid solution on this StackOverflow question , but as I said it doesn't work for me.
EDIT: I solved the problem as follows: 1. I changed this code:
<script>
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 = "https://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"));
</script>
from:
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
-
I was calling this code:
twttr.ready (function (twttr) {twttr.events.bind ('click', function (event) {alert ('yes');});});
in the wrong place in my files. I was calling it on the parent view (my ASP.NET MVC application) instead in the partial view where I had mine <a href="https://twitter.com/share" class="twitter-share-button" data-url="https://twitter.com/share" data-via="josephjohnbless">Tweet</a>
and <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
. And it was.
source to share
No one has answered this question yet
See similar questions:
or similar: