Solved

refresh item on page(iframe, table, or div)

Posted on 2006-06-08
1
512 Views
Last Modified: 2008-02-01
I would like to refresh an iframe on my website at a given interval. I have some code below. It is not working when I use the url in the src.  However, if I replace the iframe src with an image file vs a url, it works fine. Any one  know why?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <SCRIPT LANGUAGE="JavaScript">
<!--

var secs
var timerID = null
var timerRunning = false
var delay = 1000

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 25
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        self.status = ""
        // Here's where you put something useful that's
        // supposed to happen after the alotted time.
        // For example, you could display a message:
       
        refresh();
        InitializeTimer();
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

//-->
</SCRIPT>
</head>
<body onload="InitializeTimer()">
<table BORDER=0 CELLSPACING=0 CELLPADDING=0 bordercolor="#111111" >
<tr><td WIDTH="100%">
<iframe id="ifx" width="365" scrolling="No" height="340" frameborder="no" src="http://pub.camera.trafficland.com/trafficimage.php?system=ladotd&webid=2039&pubtoken=7294826e9eb4e70cbd3c86630f4186b7&0.44067952619013856"></iframe>
</td>
</tr>
</table>

<form>
  <p><input type="button" onclick="refresh()" value="Refresh Form Button"
  name="button1"></p>
</form>


<script language="JavaScript">
function refresh()
{
      document.ifx.location.reload();
}
</script>
</body>
</html>
0
Comment
Question by:LeeHenry
1 Comment
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 16866189
Here my version:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Zvonko &#42;</title>
    <SCRIPT LANGUAGE="JavaScript">
<!--

var secs
var timerID = null
var timerRunning = false
var delay = 1000
var camera = "http://pub.camera.trafficland.com/trafficimage.php?system=ladotd&webid=2039&pubtoken=7294826e9eb4e70cbd3c86630f4186b7&0.44067952619013856";
function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 25
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        self.status = ""
        // Here's where you put something useful that's
        // supposed to happen after the alotted time.
        // For example, you could display a message:
       
        refresh();
        InitializeTimer();
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

//-->
</SCRIPT>
</head>
<body onload="InitializeTimer()">
<table BORDER=0 CELLSPACING=0 CELLPADDING=0 bordercolor="#111111" >
<tr><td WIDTH="100%">
<iframe name="ifx" id="ifx" width="365" scrolling="No" height="340" frameborder="no" ></iframe>
</td>
</tr>
</table>

<form>
  <p><input type="button" onclick="refresh()" value="Refresh Form Button"
  name="button1"></p>
</form>


<script language="JavaScript">
function refresh(){
  window.frames.ifx.location=camera+"&time="+(new Date()).getTime();
}

refresh();
</script>
</body>
</html>


0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select case on click 3 20
How to deal with the query string 8 37
html input 8 42
ASP Classic - JavaScript - Get value from form in iFrame and pass to main page. 2 22
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

861 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