0

This is my code :

HTML

<a href="#" id="showTwitter">Twitter</a>
<div><a href="http://twitter.com/share" class="twitter-share-button" data-url="www.google.it" data-count="vertical" data-lang="it"><!-- --></a></div>

jQuery

$("#showTwitter").click(function() {
        $.getScript("http://widgets.twimg.com/j/2/widget.js");
});

I'd like to load the twitter plugin clicking on the link, but it will not rendered. Why? And how can I fix this?

Community
  • 1
  • 1
markzzz
  • 47,390
  • 120
  • 299
  • 507
  • $.getScript() loads and executes a script. I doubt that the twitter script runs anything just on executing that will display anything on your website. Presumably there will be other stuff you need to do, html elements to add, or functions you will need to invoke manually. – Thomas Clayson Feb 24 '12 at 09:08
  • It works like a sharm with every others social plugins, but twitter...don't know! Any ideas? – markzzz Feb 24 '12 at 09:50

2 Answers2

0

I heard of a problem like this in Chrome here: Jquery getScript($.getScript()) not working on chrome?

You probably want to load the script inline and then execute it when the link is clicked. Then there is no doubt that the browser will have all the necessary files.

You could also load everything and execute the script onload and then just hide the twitter widget and then show it when the link is clicked.

Community
  • 1
  • 1
edhurtig
  • 2,331
  • 1
  • 25
  • 26
0

Use this:

twttr.widgets.load();

source: https://dev.twitter.com/discussions/890

karenism
  • 166
  • 1
  • 8