943,172 Members | Top Members by Rank

Ad:
Sep 3rd, 2010
0

Javascript Timer IE Problem

Expand Post »
Hello.

I don't know any code of Javascript. I programme in PHP.

I grabbed this piece of code for javascript timer:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form name="counter"><input name="d2" type="text" size="8" style="font-size:72pt; border:none; font-family:Verdana; color:#00BFFF; text-outline: 1px 1px #009ACD;"></form>
  2.  
  3. <script>
  4. <!--
  5. //
  6. var milisec=0
  7. var seconds=<?php echo $s;?>
  8. document.counter.d2.value='0'
  9.  
  10. function display(){
  11. if (milisec<=0){
  12. milisec=9
  13. seconds-=1
  14. }
  15. if (seconds<=-1){
  16. milisec=0
  17. seconds+=1
  18. }
  19. else
  20. milisec-=1
  21. document.counter.d2.value=seconds
  22. setTimeout(\"display()\",100)
  23. }
  24. display()
  25. -->
  26. </script>
  27.  

Basically the count-down timer code displays seconds counting down in textbox "d2".
I've modified the code to display seconds only and no milliseconds.

After the countdown, I've used PHP.
For example: If $s=45 (let).
The code countsdown, while simultaneously, a header is sent:
header("refresh: $s; http://..../...sameurl.php?s=RANDOM_TEMP_PASSWORD");
So that page refreshes after say 45 seconds and sends itself a random password, instructing the page that timer is now set to '0' and it should show the "DOWNLOAD" button.

In Mozilla Firefox, Download button appears after refresh

However, In IE6/7/8 after refresh, the timer restarts instead of showing "Download"

Live Example: http://www.mintload.com/dl/?f=cf51a94

(Click "FREE DOWNLOAD", and see the page freedl.php on next page which has this problem on IE)

Thank you!
Similar Threads
Reputation Points: 8
Solved Threads: 0
Light Poster
akshayinbox is offline Offline
30 posts
since Aug 2009
Sep 3rd, 2010
0
Re: Javascript Timer IE Problem
Please help me fix this prob., It's really urgent.
Thanks
Reputation Points: 8
Solved Threads: 0
Light Poster
akshayinbox is offline Offline
30 posts
since Aug 2009
Sep 3rd, 2010
0
Re: Javascript Timer IE Problem
As this is urgent, iil give you the solution, but study the code and learn from your mistakes. Each code lines needs to end with a ;, use more spaces and pay attention on how I use the setTimeout() function:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. setTimeout(function(){
  2. //Here should be all the code you want executed
  3. }, 0);

And here how it is implemented:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type='text/javascript'>
  2. <!--
  3.  
  4. var milisec=0;
  5. var seconds=<?php echo $s;?>;
  6. // I directed this (document.counter.d2.value='0';) to setTimeout, as the document has not yet been loaded
  7.  
  8. function display(){
  9. if (milisec <= 0){
  10. milisec = 9;
  11. seconds -= 1;
  12. }
  13. if (seconds <= -1){
  14. milisec = 0;
  15. seconds += 1;
  16. } else {
  17. milisec-=1;
  18. document.counter.d2.value=seconds;
  19. setTimeout(function(){ display(); },100);
  20. }
  21. }
  22. window.onload=function() {
  23. document.counter.d2.value='0';
  24. display();
  25. }
  26. -->
  27. </script>

~G
Last edited by Graphix; Sep 3rd, 2010 at 12:11 pm.
Reputation Points: 82
Solved Threads: 74
Posting Pro in Training
Graphix is offline Offline
400 posts
since Aug 2009
Sep 5th, 2010
0
Re: Javascript Timer IE Problem
The full code (PHP + Javascript on timer3.php) s here:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. session_start();
  4.  
  5.  
  6. $f=$_GET['f'];
  7. $dlpath=urlencode($_GET['dlpath']);
  8.  
  9. $s=waitfor(); //function returns how many seconds to wait.
  10. $link='<a href="http://mintload.com/dl/launchdl.php?f='.$f.'&dlpath='.$dlpath.'&sessid='.$sessid.'" target="_blank"><img width=195 height=45 src="http://mintload.com/images/btn_download.png" alt="Download!" border=0></a>';
  11.  
  12. global $zerowait;
  13. $zerowait=md5("secret_password".session_id()); //temperory session-id based password (hash) instructing that seconds to wait is 0.
  14.  
  15. if($_GET['s']!=$zerowait)
  16. {
  17. //Display seconds, and after $s seconds (returned by func) , refresh the page.
  18. header("refresh: $s; http://mintload.com/dl/timer3.php?s=".$zerowait."&f=$f&dlpath=$dlpath&sessid=$sessid");
  19. echo '<form name="counter"><input type="text" size="8" style="font-size:72pt; border:none; font-family:Verdana; color:#00BFFF; text-outline: 1px 1px #009ACD;" name="d2"></form>';
  20.  
  21. }
  22. else {
  23. //if $s=-zerowait, set seconds to 0 (stops javascript timer), display "download" button ($link), and exit rest of script
  24.  
  25. $s=(int)0;
  26. echo $link;
  27. exit;
  28. }
  29.  
  30. echo "
  31.  
  32. <script>
  33. <!--
  34. //
  35. var milisec=0
  36. var seconds=$s
  37. document.counter.d2.value='0'
  38.  
  39. function display(){
  40. if (milisec<=0){
  41. milisec=9
  42. seconds-=1
  43. }
  44. if (seconds<=-1){
  45. milisec=0
  46. seconds+=1
  47. }
  48. else
  49. milisec-=1
  50. document.counter.d2.value=seconds
  51. setTimeout(\"display()\",100)
  52. }
  53. display()
  54. -->
  55. </script>";
  56.  
  57.  
  58. function waitfor() {
  59.  
  60. //Code suppressed as it works fine (waitfor())
  61.  
  62. /* Basically what function does is:
  63. if premium user, $s=0;
  64. if free users, $s=30;
  65. if unregistered user, $s=45;
  66. return $s;
  67. */
  68.  
  69. } //func ends
  70.  
  71. ?>

Now, could u please relate and help???

Thank you!
Reputation Points: 8
Solved Threads: 0
Light Poster
akshayinbox is offline Offline
30 posts
since Aug 2009
Sep 5th, 2010
0
Re: Javascript Timer IE Problem
Look, I was willing to correct your code and remove the syntax errors. Apply my code, and work the PHP out yourself. The JavaScript timer should work. Also check the HTML source code for wrong output.

~G
Reputation Points: 82
Solved Threads: 74
Posting Pro in Training
Graphix is offline Offline
400 posts
since Aug 2009
Sep 5th, 2010
0
Re: Javascript Timer IE Problem
The only error in my script was:
header("refresh: $s; http:/....");

should BE:
header("refresh: $s url=http:/..."); //WORKS IN ALL BROWSERS! Those 3 letters, url

anyway, Thanks all those who helped
Reputation Points: 8
Solved Threads: 0
Light Poster
akshayinbox is offline Offline
30 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript Not Working in Firefox
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: forms: Multiple Destinations depending on combo of Multiple Select Boxes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC