1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help With code

Discussion in 'FaceBook' started by DNK13, Dec 29, 2010.

  1. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    Can someone help me with making code that for example after 5 seconds will show hidden text

    thanks
     
  2. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    Is this just in a HTML page?
     
  3. ericsson

    ericsson Elite Member Premium Member

    Joined:
    Apr 25, 2009
    Messages:
    2,642
    Likes Received:
    8,132
    Occupation:
    www
    Location:
    Swe
    Home Page:
    I like your avatar man. :)
    Is that you?
     
  4. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    its FBML but i think that this code must be in FBJS
     
  5. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    LOL, I wish - nah, he is Frank out of Shameless, one of the best TV shows....

    Anyway - to the OP, if you visit:
    Code:
    http://fatboy.me.uk/delay
    you should see what you are after. Its not my own code, its bits I have 'borrowed' from other websites over the years.

    If its what you want, just view the source :)
    To change the delay, find the 5000 in the source and change it to what you want - 5000 equals 5 seconds.

    Never played with FB code sorry - hopefully you can get my code to work in there :)

    Cheers :)
     
    Last edited: Dec 29, 2010
  6. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    thanks alot
    i will try that code
     
  7. GreyWolf

    GreyWolf Executive VIP Jr. VIP

    Joined:
    Aug 17, 2009
    Messages:
    1,930
    Likes Received:
    5,389
    Gender:
    Male
    Occupation:
    Artist / Craftsman
    Location:
    sitting at my PC
    Here's how you can do that with javascript on a regular html page.
    Code:
    <html>
    <head>
    <title>Hidden text will show 5 seconds after page load</title>
    
    <script type="text/javascript">
    <!--
    function ShowHidden(id) {
        obj = document.getElementsByTagName("div");
        setTimeout("ShowHidden('HiddenDiv')",5000);
        obj[id].style.visibility = 'visible';
       }
    onload = ShowHidden
    //-->
    </script> 
    
    <style type="text/css">
    <!--
    #HiddenDiv
    {
    visibility:hidden;
    width:100px;
    height:100px;
    position:absolute;
    left:200px;
    top:20px;
    border:1px;
    }
    
    -->
    </style>
    
    </head>
    <body>
    
    <div id="HiddenDiv">Here is the hidden text you want to show</div>
    
    </body>
    </html>
    Just change the px sizes in the div box to whatever you want it to be to fit your text. You can change the 5000 in the timeout to whatever you want. (1 second = 1000)

    I've never done anything in fbml so you need to figure that part on your own. FBML does have some limitations on javascript though. If you're wanting to use javascript in a profile box then inline scripts won't work until the first user event. On a canvas page though you should be able to adapt it to work.

    You can check here for specifics on how to use javascript in FBML.
    hxxp://wiki.developers.facebook.com/index.php/FBJS

    edit- I see fatboy gave you an answer while I was making my reply. So that gives you two possible javascript solutions. You just need to figure how to adapt one to work in fbml.
     
    • Thanks Thanks x 1
    Last edited: Dec 29, 2010
  8. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    thanks alot :)

    i have problem,when i put code on fbml code tester code work but when i try on face then code dont show hidden content
     
  9. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    Yup, but yours looks better than mine which was lashed together from a couple of places :D I am not that hot at HTML, CSS or Javascript!!

    I copied your code down for future use as well :)
     
    • Thanks Thanks x 1
  10. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    i cant make it work
    does somebody know how to configure style in fbml because it dont support regular code for style
     
  11. GreyWolf

    GreyWolf Executive VIP Jr. VIP

    Joined:
    Aug 17, 2009
    Messages:
    1,930
    Likes Received:
    5,389
    Gender:
    Male
    Occupation:
    Artist / Craftsman
    Location:
    sitting at my PC
    If you can get it to work in the fbml code tester then you should be able to get it working on the live page too. It's probably just some kind of stupid formatting problem like a line feed messing it up or something. Things like that can be frustrating as hell when dealing with php scripts. Maybe fbml has similar quirks.

    I haven't actually made anything in fbml, so I can't really test that part out for you. I did find this bit of info regarding using javascript in fbml.
    If that doesn't help and someone good with fbml doesn't come in the thread then you'll just need to look through the fbml faq pages.

    here's the page explaining about using javascript in fbml where I found those quotes. It's for a completely different script example, but the suggestions on how to set up the script should still help you.
    Code:
    http://stackoverflow.com/questions/1866731/can-javascript-be-used-in-static-fbml-under-pages-tab

    Hopefully someone else good with fbml will come in the thread who can explain how to make the javascript work.

    Good Luck :smokin:
     
    Last edited: Dec 29, 2010
  12. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    im trying to convert but i dont know what im doing wrong,when i check code on site for test fbml code all works normally but when i put that code on my fan page then code dont work
     
  13. phph5

    phph5 Regular Member

    Joined:
    Aug 7, 2010
    Messages:
    225
    Likes Received:
    42
    You can't use timers on Static FBML without user interaction first. A timer can only be activated once a user clicks somewhere on the page/perfomrs an action.

    Here's the code snippet you need for that: (note that you should always wrap actions in a function, a very common mistake).

    Code:
    setTimeout(function()  { your_function_todisplay_text(); },1000);
    Replace your_function_todisplay_text(); with your function.
    1000 = 1 second, 5000 = 5 seconds etc.

    HTH
     
    • Thanks Thanks x 2
  14. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    In addition to script execution being delayed untill an event is triggered by a user, manipulation of DOM objects in FBJS (Facebook Javascript) is handled differently as well. You will want to use the fbjs setter 'setStyle'. Basically this is the grey's code code keeping in mind with what php5 mentioned and using the proper fbjs setter.

    Code:
    <style type="text/css">
    <!--
    #HiddenDiv
    {
    visibility:hidden;
    }
    -->
    </style>
    
    <a href="#" onclick="setTimeout(show_hidden,5000);">Show Hidden!</a>
    
    <div id="HiddenDiv">Here is the hidden text you want to show</div>
    
    <script> 
    <!-- 
    
    function show_hidden() { 
    document.getElementById('HiddenDiv').setStyle('visibility', 'visible');
    } 
    
    //--> 
    </script>
    
     
    • Thanks Thanks x 2
  15. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    one question
    can this code be modified that when i press button it redirect me to some other site in new tab and also show hidden content below button?
    or button can be used only for one function?

    Code:
    <a  class="UIButton UIButton_Gray UIActionButton" clicktoshow="{[B]id[/B]}"><span class="UIButton_Text">Next Step</a>
    <div id="{[B]id[/B]}" style="display:none">yeaa baby</div>
     
  16. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    thanks alot for this code,that is what im looking for :)
     
  17. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    Your welcome. :)

    No I don't belive you can use the clicktoshow attribute along with an href like that.
    You can do something similar with the code I posted above however.
    Code:
    <a href="http://www.google.com/" target="_blank" onclick="setTimeout(show_hidden,5000);">Show hidden and open in new tab!</a>
     
    • Thanks Thanks x 1
  18. DNK13

    DNK13 Newbie

    Joined:
    Dec 28, 2010
    Messages:
    15
    Likes Received:
    1
    Thanks alot for your help

    now all works perfectly :)