Help With code

DNK13

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

thanks
 
I like your avatar man. :-)
Is that you?

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:
LOL, I wish - nah, he is Frank out of Shameless, one of the best TV shows....

Anyway - to the OP, if you visit:------------------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 :)
thanks alot
i will try that code
 
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.
 
Last edited:
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
 
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.

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 :)
 
i cant make it work
does somebody know how to configure style in fbml because it dont support regular code for style
 
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
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.
"In profile boxes, inline scripts are deferred until the first "active" event is triggered by a user. An active event is considered either onfocus, onclick, onmousedown, and so forth. Basically anything that requires a mouse click is an "active" event. On a canvas page, however, this example works just fine."
the wiki page mentions that code should be setup like this: <script> <!-- //--> </script> try inserting your FBJS within these script tags like so: <script> <!-- document.getElementById('button1').setStyle({display: 'none'}); //--> </script>
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:
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
 
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

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
 
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>
 
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>
 
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 alot for this code,that is what im looking for :)
 
Your welcome. :)

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>

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>
 
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.
............
Thanks alot for your help

now all works perfectly :)
 
Back
Top