www.webdeveloper.com
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2006
    Posts
    4

    Auto Refresh Frame Help?

    Hi i have this script to auto refresh my webpage, it has a countdown timer.

    My website is in 2 frames, and i only want the bottom frame to refresh but i want the timer in the top frame.

    at the moment the code is in my top.php witch is the header frame, if i place in the index.php (main body frame) it doesnt work properly.

    example http://devstudio.co.uk/

    Is there a way of doing this?

    thanks in advance for any help.

    Tony-H

    javascript

    Code:
    <script language="JavaScript">
    
    //configure refresh interval (in seconds)
    var countDownInterval=60;
    //configure width of displayed text, in px (applicable only in NS4)
    var c_reloadwidth=200
    
    </script>
    
    
    <ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>
    
    <script>
    
    var countDownTime=countDownInterval+1;
    function countDown(){
    countDownTime--;
    if (countDownTime <=0){
    countDownTime=countDownInterval;
    clearTimeout(counter)
    window.location.reload()
    return
    }
    if (document.all) //if IE 4+
    document.all.countDownText.innerText = countDownTime+" ";
    else if (document.getElementById) //else if NS6+
    document.getElementById("countDownText").innerHTML=countDownTime+" "
    else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
    document.c_reload.document.c_reload2.document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
    document.c_reload.document.c_reload2.document.close()
    }
    counter=setTimeout("countDown()", 1000);
    }
    
    function startit(){
    if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
    document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
    countDown()
    }
    
    if (document.all||document.getElementById)
    startit()
    else
    window.onload=startit
    
    </script>
    top.php

    Code:
    <?php include("common.php"); ?>
    
    <html>
    <head>
    <title><?php echo $site_title ?></title>
    
    <script language="JavaScript">
    
    //configure refresh interval (in seconds)
    var countDownInterval=10;
    //configure width of displayed text, in px (applicable only in NS4)
    var c_reloadwidth=200
    
    </script>
    
    
    <ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>
    
    <script>
    
    var countDownTime=countDownInterval+1;
    function countDown(){
    countDownTime--;
    if (countDownTime <=0){
    countDownTime=countDownInterval;
    clearTimeout(counter)
    window.location.reload()
    return
    }
    if (document.all) //if IE 4+
    document.all.countDownText.innerText = countDownTime+" ";
    else if (document.getElementById) //else if NS6+
    document.getElementById("countDownText").innerHTML=countDownTime+" "
    else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
    document.c_reload.document.c_reload2.document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
    document.c_reload.document.c_reload2.document.close()
    }
    counter=setTimeout("countDown()", 1000);
    }
    
    function startit(){
    if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
    document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
    countDown()
    }
    
    if (document.all||document.getElementById)
    startit()
    else
    window.onload=startit
    
    </script>
    
    <link href="styles.css" rel="stylesheet" type="text/css">
    </head>
              </tr>
              <tr> 
                <td valign="top" background="images/bg.jpg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td width="100%" colspan="2" valign="top"><TABLE cellSpacing=0 cellPadding=0 width=770 border=0>
                          <TBODY>MY HEADER
    
    </body>
    </html>
    index.php

    Code:
    <?
    srand((double)microtime()*1000000);
    function randString($l) {
    if($l==0)
    return "";
    else
    return randChar().randString($l-1);
    }
    
    function randChar() {
    $str = "01234";
    return substr($str, rand(0, strlen($str)-1), 1);
    }
    
    $random_number = randstring(1);
    
    if ($random_number=="0") {$site="http://www.partyspotters.com";}
    if ($random_number=="1") {$site="http://www.ukche.com";}
    if ($random_number=="2") {$site="http://www.partyspotters.com";}
    if ($random_number=="3") {$site="http://www.ukche.com";}
    if ($random_number=="4") {$site="http://www.ukche.com";}
    
    
    print <<<EOT
    
    
    
    <frameset rows="140,*" frameborder="NO" border="0" framespacing="0">
    <frame src="top.php" name="topFrame" scrolling="NO" noresize >
    <frame src="$site" name="mainFrame">
    </frameset>
    
    
    
    EOT;
    
    ?>

  2. #2
    Join Date
    Dec 2005
    Location
    Queen Creek, AZ
    Posts
    1,564
    use:

    window.top.frames('nameofframe').src = window.top.frames('nameofframe').src;
    Design first! Code later!

  3. #3
    Join Date
    Jan 2006
    Posts
    4
    thnaks for your help, but excuse my lack of knowledge , where am i putting the code you supplied?

    Thanks

  4. #4
    Join Date
    Jan 2006
    Posts
    4
    hmm i kinda got it working, but sometimes the syncing with refresh and timer is out

    any idea how to sync the refresh? this is tottally baffling my brain, and the way its coded right now is very messy,

    http://devstudio.co.uk/


    my 3 files now are


    thanks in advance for any help, anyone ..

    top.php

    Code:
    <?php include("common.php"); ?>
    
    <html>
    <head>
    <title><?php echo $site_title ?></title>
    
    <script language="JavaScript">
    
    //configure refresh interval (in seconds)
    var countDownInterval=20;
    //configure width of displayed text, in px (applicable only in NS4)
    var c_reloadwidth=200
    
    </script>
    
    
    <ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>
    
    <script>
    
    var countDownTime=countDownInterval+1;
    function countDown(){
    countDownTime--;
    if (countDownTime <=0){
    countDownTime=countDownInterval;
    clearTimeout(counter)
    window.location.reload()
    return
    }
    if (document.all) //if IE 4+
    document.all.countDownText.innerText = countDownTime+" ";
    else if (document.getElementById) //else if NS6+
    document.getElementById("countDownText").innerHTML=countDownTime+" "
    else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
    document.c_reload.document.c_reload2.document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
    document.c_reload.document.c_reload2.document.close()
    }
    counter=setTimeout("countDown()", 1000);
    }
    
    function startit(){
    if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
    document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds')
    countDown()
    }
    
    if (document.all||document.getElementById)
    startit()
    else
    window.onload=startit
    
    </script>
    
    <link href="styles.css" rel="stylesheet" type="text/css">
    </head>
    <body>
              </tr>
              <tr> 
                <td valign="top" background="images/bg.jpg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr> 
                      <td width="100%" colspan="2" valign="top"><TABLE cellSpacing=0 cellPadding=0 width=770 border=0>
                          <TBODY>MY HEADER
    
    </body>
    </html>
    index.php

    Code:
    <frameset rows="140,*" frameborder="NO" border="0" framespacing="0">
    <frame src="top.php" name="topFrame" scrolling="NO" noresize >
    <frame src="bottom.php" name="mainFrame">
    </frameset>
    bottom.php

    Code:
    <META HTTP-EQUIV="Refresh"
    CONTENT="20;">
    <?
    srand((double)microtime()*1000000);
    function randString($l) {
    if($l==0)
    return "";
    else
    return randChar().randString($l-1);
    }
    
    function randChar() {
    $str = "01234";
    return substr($str, rand(0, strlen($str)-1), 1);
    }
    
    $random_number = randstring(1);
    
    if ($random_number=="0") {$site="http://www.partyspotters.com";}
    if ($random_number=="1") {$site="http://www.ukche.com";}
    if ($random_number=="2") {$site="http://www.google.com";}
    if ($random_number=="3") {$site="http://www.yahoo.com";}
    if ($random_number=="4") {$site="http://www.msn.com";}
    
    
    print <<<EOT
    
    
    <frameset " frameborder="NO" border="0" framespacing="0">
    <frame src="$site" name="mainFrame">
    </frameset>
    
    
    
    
    
    EOT;
    
    ?>

  5. #5
    Join Date
    Dec 2005
    Location
    Queen Creek, AZ
    Posts
    1,564
    I can't actually see where you change the bottom frame at all.

    For your bottom.php using mt_rand() as your randomize function is more efficient and much faster.

    Your bottom.php file could be condensed into a bout 6 lines or so.
    Design first! Code later!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



Recent Articles