Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Refresh iFrame Only - PHP clock 1

Status
Not open for further replies.

Muppsy007

Programmer
Apr 4, 2003
98
NZ
Hello, I'm guessing this is best sorted using JS so I asked it here after searching the site.

Here is what I am doing:

I have a php page called "time.php" that simply gets the server time and displays it.

Code:
time.php

<?php
	printf("serverTime=%d000", time());
?>

I have a second page called "clock.php". This page will eventually have a flash analog clock on it that displays the server time using the time.php script. As the time.php page needs to be refreshed every second, I thought the only way to refresh it with out reloading the entire page is to put the time.php script into an iFrame and refresh that.

Code:
clock.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
<!--
body {
	background-color: #003399;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">


<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>


</head>

<body>

<iframe src="time.php" style="margin-left: 30px;" frameborder="0" id="time" name="time" height="40" width="290" hspace="0" vspace="0" scrolling="no"></iframe>

</body>
</html>

I'll keep it basic for now, so don't worry about the flash clock, all I want to do for now, is display the output of the time.php page in the iframe and refresh that iframe every second.

I have tried putting the meta refresh tag in the time.php page, which works, but it seems to refresh the entire clock.php too. (The status bar looks that way anyway and the hourglass mouse pointer comes up every second)

Is there away that I can just refresh time.php in iframe by itself?

Thanks
Aaron
 
The status bar probably will look like the whole page has reloaded but it probably isn't. Write the date into the main window and the iframe and it should be easy enough to tell. Use something like:
Code:
var date = new Date();document.write(date.getTime());

You could refresh the iframe with Javascript (example below) but you'll still get the 'loading...' thing on the status bar.

Here's that example:
Code:
function refreshIframe() {

	ifr = document.getElementsByTagName( "iframe" )[ 0 ];
	ifr.src = ifr.src;

	setTimeout( refreshIframe, 1000);
}

window.onload = refreshIframe;
 
Thanks mate. I've added a whole lot of content to the page and tested it, and it is as you say. The iframe is reloading, and it status bar is just making it look like the whole page is.

No worries, I've decided to stick with what I've got and remove the second hand from the flash clock and just refresh the iFrame every 60secs instead.

Cheers
Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top