Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Twitter buttons

  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts

    Twitter buttons

    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?
    Code:
    <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.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,640
    Thanks
    6
    Thanked 1,004 Times in 977 Posts
    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?

    Edit: 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.
    Last edited by VIPStephan; 05-31-2012 at 06:34 PM.

  • #3
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts
    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.

    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?
    Last edited by quartzy; 06-02-2012 at 02:24 PM.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,640
    Thanks
    6
    Thanked 1,004 Times in 977 Posts
    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.:
    Code:
    <script type="text/javascript">
    // <![CDATA[
    (any JavaScript comes here)
    // ]]>
    </script>
    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.

  • #5
    Regular Coder
    Join Date
    May 2009
    Posts
    813
    Thanks
    123
    Thanked 24 Times in 24 Posts
    Thanks for your help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •