So far I've got this iframe to refresh every minute. What I would like to do is have the scr of the iframe be a variable. When the iframe loads to the main site if it find that the page cannot be dislayed then switch to the second site. I am very new to javascript and any help would be very appreciated. Thanks in advance.

<html>
<head><title></title></head>
<body>

<!--start refresh ackpage1 iframe-->
<script type=text/javascript>
function refresh()
	{document.all.ackpage1.src = document.all.ackpage1.src;}
	window.setInterval("refresh()",60000);
</script>
<!--end refresh ackpage1 iframe-->

<iframe src="https://www.sitehere.com" style="zoom:100%" id="ackpage1" name="ackpage1" width="490" height="390" scrolling="yes" align="right" frameborder="no" marginheight="0" marginwidth="0"></iframe>
</body>
</html>

Recommended Answers

All 3 Replies

This http://home.comcast.net/~dyscdbc/NoName02.html is the URL of a working demo, and here

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 25 March 2009), see www.w3.org">
    <title></title>
    <script type="text/javascript">

        var getURL = "http://home.comcast.net/~dyscdbc/A.HTM"
        var altURL = "http://home.comcast.net/~dyscdbc/AR.HTM"

        function ckFrm() {
            var gotURL = window.frames['ackpage1'].window.location
            if (gotURL != getURL) {
                alert(gotURL)
                window.frames['ackpage1'].window.location = altURL
            }
        }

    </script>
  </head>
  <body onload="ckFrm()">
    <iframe src="http://home.comcast.net/~dyscdbc/B.HTM" style=
    "zoom:100%" id="ackpage1" name="ackpage1" width="490" height=
    "390" scrolling="yes" align="right" frameborder="no"
    marginheight="0" marginwidth="0"></iframe>
  </body>
</html>

is the code.

Some notes:

1. to trigger this demo, at line 23 I specify a src= page that does not exist in my domain. If this were a real application that src= and the value of getURL at line 9 would be the same.

2. when onload= occurs, ckFrm() compares the .location of the named iframe (the page currently being dislayed in it) to the expected value.

3. since the iframe was deliberately given a 'wrong' URL, it is now displaying a 404 page from the server (the URL of which [as shown in the alert] does not match getURL).

4. the .location of the iframe window is now changed (to a page that exists, which then appears).

I also have some comments about your code and the basic concept; I will post those later this morning.

I have a couple of comments, then another demo.

First, it is a Good Idea to avoid document.all ; where it happens to work, it is deprecated, where it doesn't work - well, it doesn't work.

Refreshing the entire page is overkill; it is only necessary to cause the IFRAME to reload.

This working demo http://home.comcast.net/~dyscdbc/NoName01.html illustrates both points, and here

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta name="generator" content=
    "HTML Tidy for Windows (vers 25 March 2009), see www.w3.org">
    <title></title>
    <script type="text/javascript">

        var getURL = "http://home.comcast.net/~dyscdbc/A.HTM"
        var altURL = "http://home.comcast.net/~dyscdbc/AR.HTM"
        var intID;

        function pokeIT() {
            window.frames['ackpage1'].window.location = window.frames['ackpage1'].window.location
        }

        function stopIT() {
            clearInterval(intID)
        }

        function ckFrm() {
            var gotURL = window.frames['ackpage1'].window.location
            if (gotURL != getURL) {
                window.frames['ackpage1'].window.location = altURL
            }
            intID = setInterval('pokeIT()', 6000)
        }

    </script>
  </head>
  <body onload="ckFrm()" onclick="stopIT()">
    <iframe src="http://home.comcast.net/~dyscdbc/B.HTM" style=
    "zoom:100%" id="ackpage1" name="ackpage1" width="490" height=
    "390" scrolling="yes" align="right" frameborder="no"
    marginheight="0" marginwidth="0"></iframe>
  </body>
</html>

is the code.

commented: Went above and beyond!!!! +0

Thank you so much for your help. That code there is a thing of beauty!! I really appreciated the working demo. It helps alot when I can see the code in action.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.