Solved

Reload page with current time as URL parameter

Posted on 2014-09-25
2
171 Views
Last Modified: 2014-09-25
I wrote two functions in javascript. The first function displays the current time on the screen. The second takes that time and reloads the page after 5 seconds sending the current value as a URL parameter. Except once I put in the variable the .window.location stops working.

I am not very experienced with javascript and can not seem to figure what I am doing wrong. Here is the code:

<!DOCTYPE html> 
<html> 
<head> 
<script> 
function currentTime() { 
var today=new Date(); 
var Y=today.getFullYear(); 
var M=today.getMonth(); 
var D=today.getDate(); 
var h=today.getHours(); 
var m=today.getMinutes(); 
var s=today.getSeconds(); 
m = checkTime(m); 
s = checkTime(s); 

document.getElementById('clock').innerHTML = Y+ "-"+M+ "-"+D+ " "+h+":"+m+":"+s; 
var t = setTimeout(function(){currentTime()},500); 
} 

function checkTime(i) { 
if (i<10) {i = "0" + i}; // add zero in front of numbers < 10 
return i; 
} 
</script> 

<script> 
<!-- 
function Redirect() 
{ 
window.location.replace = “page.html?var=" Y+ "-"+M+ "-"+D+ " "+h+":"+m+":"+s; 
} 

setTimeout('Redirect()', 5000); 
// 
</script> 
</head> 


<body onload="currentTime()"> 
<div id="clock"></div> 
</body> 
</html> 

Open in new window


Any help would be appreciated.
0
Comment
Question by:serviceco
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40344300
<!DOCTYPE html> 
 <html> 
 <head> 
 <script> 

 var today,Y,M,D,h,m,s; 

 function currentTime() { 
 today=new Date(); 
 Y=today.getFullYear(); 
 M=today.getMonth(); 
 D=today.getDate(); 
 h=today.getHours(); 
 m=today.getMinutes(); 
 s=today.getSeconds(); 
 m = checkTime(m); 
 s = checkTime(s); 
 document.getElementById('clock').innerHTML = Y+ "-"+M+ "-"+D+ " "+h+":"+m+":"+s; 
 var t = setTimeout(function(){currentTime()},500); 
 } 

 function checkTime(i) { 
 if (i<10) {i = "0" + i}; // add zero in front of numbers < 10 
 return i; 
 } 
 </script> 

 <script> 
 <!-- 
function Redirect() 
 {
 window.location.replace("page.html?var="+ Y + "-"+M+ "-"+D+ " "+h+":"+m+":"+s); 
 } 

 setTimeout('Redirect()', 5000); 
 // 
 </script> 
 </head> 


 <body onload="currentTime()"> 
 <div id="clock"></div> 
 </body> 
 </html> 

Open in new window

0
 

Author Closing Comment

by:serviceco
ID: 40344430
Thank you!  I understand what I missed. I appreciate the help.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question