View Full Version : Twitter buttons

05-31-2012, 01:22 PM
I am trying to add a twitter button to a charity website www.lewishamctscheme.org.uk but the button does not work in many browsers if any, even though the twitter pages says it does. Can anyone help?
<a href="https://twitter.com/LewishamCT" class="twitter-follow-button" data-show-count="false">
Follow @LewishamCT</a><script>/* <![CDATA[ */!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");]]>/* ]]> */
</script><noscript><p>Your browser does not support Javascript, please tweet using the link</p></noscript></p>

Is it because Twitter buttons does not work on xhtml strict? Any help really appreciated.

05-31-2012, 07:28 PM
Twitter buttons work anywhere. Did you follow the rules on https://dev.twitter.com/docs/follow-button or do it via http://twitter.com/about/resources/buttons#follow? The script element, however, requires a type attribute with value “text/javascript” which you apparently failed to include. Also, make sure you deactivate all script blocking browser add-ons you might have.

Also, what is the purpose of the noscript there? The link already reads “Follow @LewishamCT” for those users with JS disabled. Wouldn’t you think they are smart enough to click it all by themselves?

Oh, I just noticed your link. Look at the browser’s JavaScript/error console, it gives me a big red error ‘x’ and says “Syntax error”. Look at the end of the line of the script: you have included the closing CDATA marker twice, once in a comment and once outside, before the comment and right after the ending semicolon of the JS function. Remove that one, it’s causing the error.

06-02-2012, 03:19 PM
Thank you for pointing these out I will get to them. I have reposted now and I have four errors as I could not find this post I had not subscribed. I guess I do not need the noscript tags on it after all. I did check the developer rules but did not know there was anything else I will check it out again. Just thought it was a matter of copy and paste the code.

<a href="https://twitter.com/twitterapi" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow @twitterapi</a>
<script type="text/javascript">!function (d, s, id) {var js, fjs = d.getElementsByTagName(s)[0]; if (!d.getElementById(id)) {js = d.createElement(s); js.id = id; js.src = "http//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); } }(document, "script", "twitter-wjs");</script>

As I also have the facebook script don't I need to add the cdata twice?

06-02-2012, 04:39 PM
The CDATA markers are only needed in XHTML and only at the beginning and end of each section that you want to be interpreted as character data (that’s what it stands for), i. e.:

<script type="text/javascript">
// <![CDATA[
(any JavaScript comes here)
// ]]>

If you have a new script block (i. e. another script element with contents) then, of course, you need another CDATA section, but inside the script tags you just need it once and put all your JS in between.

06-04-2012, 12:25 AM
Thanks for your help