Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Countdown until content show script HELP
Old 09-06-2007, 01:09 PM Countdown until content show script HELP
Skilled Talker

Posts: 87
Trades: 0
Hi fist of all thanks for looking rely appreciate it ,

I am using a small peice of javascript (bellow) on http://gamesvolcano.com game pages,

It basically delays the content from showing for a couple of seconds in my case the flash game, my problem is i want the jscript to say "game will load in 3 seconds" while the countdown is taking place, (similar to what you find on megaupload and rapid share before you get your download link,

Code:
 <div id="my_div"></div>

<script type="text/javascript">
(function(){
var element_id = 'my_div' ; //name of div or object that you want the link to appear in (Div is best)
var link_text = '<a href="http://www.robertgarford.com/">Hello<\/a>'; //link code
var time = 3; //time in seconds until display
setTimeout(function(){document.getElementById(element_id).innerHTML = link_text;},time*1000);
})();
</script>
Any help at all, Thanks
__________________
LOADS OF FREE GAMES FOR YOUR SITE @
Please login or register to view this content. Registration is FREE

Last edited by higgylm; 09-06-2007 at 01:40 PM..
higgylm is offline
Reply With Quote
View Public Profile Visit higgylm's homepage!
 
 
Register now for full access!
Old 09-06-2007, 01:31 PM Re: Countdown until content show script HELP
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Ok, you are almost there:

1) function()
This create an anonymous function, it's usually used in asynchronous calls, to define directly what action should be done upon reception of datas.
In your case, you want a named function, declared by "function myName(){"

2) setTimeout
SetTimeout works by calling a defined action after a defined timeout. In that extent, you need to give a string to it, that it will call after the timeout. An anonymous function won't work here.

3) When you define named functions, you must call them, or make them called upon an event (click, load, mouseover...). In my code, I call it directly after defining the function.

4)Look out for syntax.
In the link_text variable, you have a <\/a> at the end. This is wrong and should be </a>. The slash won't interfere with other characters.

In that case, the script should rather be placed at the end of the page, and after the element to show.
Otherwise, on a slow pc, you could have the situation that the function try to set the innerHtml of an element that is still not loaded.

There is 1 implementation of what you want:
Code:
function countDown(){
  var element_id = 'my_div' ; //name of div or object that you want the link to appear in (Div is best)
  var link_text = '<a href="http://www.robertgarford.com/">Hello</a>'; //link code
  var time = 3; //time in seconds until display
  setTimeout('document.getElementById("'+element_id+'").innerHTML = '+link_text;},time*1000);
}

countDown();
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 09-06-2007 at 01:33 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-06-2007, 01:47 PM Re: Countdown until content show script HELP
Skilled Talker

Posts: 87
Trades: 0
Thanks thats tidies the script up for me but is it possible to adapt it so that it says "LOADING" during the 3 second count down?

I dont know very much at all about jscipt and i didnt write that simple code so please bear with me

Thanks for your help tripy
__________________
LOADS OF FREE GAMES FOR YOUR SITE @
Please login or register to view this content. Registration is FREE
higgylm is offline
Reply With Quote
View Public Profile Visit higgylm's homepage!
 
Old 09-06-2007, 01:50 PM Re: Countdown until content show script HELP
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Why not simply write "loading" in the div, before you update it's content ?
Otherwise, simply do a innerHtml before the setTimeout
Code:
document.getElementById(element_id).innerHTML ='Loading...';
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 09-06-2007 at 01:51 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-06-2007, 01:54 PM Re: Countdown until content show script HELP
Skilled Talker

Posts: 87
Trades: 0
Thanks , im not to good at jscript but if there there is any small design work you need doing in return give me a shout

Thanks again
__________________
LOADS OF FREE GAMES FOR YOUR SITE @
Please login or register to view this content. Registration is FREE
higgylm is offline
Reply With Quote
View Public Profile Visit higgylm's homepage!
 
Old 09-06-2007, 04:32 PM Re: Countdown until content show script HELP
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
You're welcome.
And trust me, I won't forget that offer (But I won't overuse it neither)
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Countdown until content show script HELP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17072 seconds with 12 queries