Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Location
    MD, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help Needed - Jscript Redirect

    I have a simple request.. I hope. I am using a redirect that is a simple schedule redirect. It works fine, and I want to alter it slightly to add a start time and an end time. It schedules the page for a particular date of the week. I need to have this page replaced at 12 noon on 7/17/03, and I need it to be back up in the am of 7/21.

    How do I incorporate the time into this script?

    <script language="JavaScript" type="text/JavaScript">
    <!--
    function pagetime(yy, mm, dd, length, url, target) {
    mm = parseInt(mm, 10);
    dd = parseInt(dd, 10);
    mm -= 1;
    var day = 86400000;
    var week = day * 7;
    var today = (new Date()).getTime();
    var start = (new Date(yy, mm, dd)).getTime();
    var future = new Date(start + (day * length));
    if (today >= start && today <= future) {
    if (target) {
    eval("parent." + target + ".location.replace(url)");
    } else {
    eval("parent.location.replace(url)");
    }
    }
    document.MM_returnValue = false;
    }
    //-->
    </script>

    <body onLoad="pagetime('2003','07','14','3','Templink.htm','');return document.MM_returnValue">
    </body>

    Any assistance is appreciated.

    Thank you,
    Last edited by Mria; 07-10-2003 at 03:51 PM.
    Mria

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Please try the following script.

    The date and time are altered in the Target_Date array

    The url's are placed in the Set_Url array




    <HTML>
    <HEAD>
    <TITLE>Document Title</TITLE>

    <script language="Javascript">
    <!--
    // Realise by jeff
    // www.huntingground.freeserve.co.uk
    // any modifications would be gratefully received
    Count= -1
    Display_period=5 // number of days to show last URL

    // Enter new date using the format year,month,day,hours,minutes,seconds
    // The month value must be between 0 and 11.
    // 00 = January, 01 = February, 02 = March etc.
    Target_Date=new Array()
    Target_Date[Target_Date.length] = new Date(2003,06,17,12,00,01) // target date 1
    Target_Date[Target_Date.length] = new Date(2003,06,21,00,00,01) // target date 2

    // enter URL to correspond with appropriate Target_Date[index]
    Set_Url=new Array()
    Set_Url[Set_Url.length]="templink.htm"
    Set_Url[Set_Url.length]="oldpage.htm"

    today=new Date() // get current date



    function Countdown(){
    for(i=0;i<Target_Date.length;i++){ // look through Target_Date array
    if(today>Target_Date[i]){ // if current date greater than Target_Date[i]
    Count++ // increment count by one
    }
    }

    if(Count>Target_Date.length-1){ // if count exceeds Target_Date length
    Count=Target_Date.length // keep count at Target_Date length
    }

    Where_To()
    }

    function Where_To(){
    if(Count== -1){
    return
    }

    Last_Entry_Date =Target_Date[Target_Date.length-1]
    Days_Expired=Math.floor((today-Last_Entry_Date)/86400000)

    loc=Set_Url[Count]
    location=loc

    }
    // include onload="Countdown()" in the opening BODY tag
    // -->
    </script>
    </HEAD>
    <BODY onload="Countdown()">

    </BODY>
    </HTML>

    Last edited by Mr J; 07-11-2003 at 04:35 PM.

  • #3
    New to the CF scene
    Join Date
    Jul 2003
    Location
    MD, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help Needed - Jscript Redirect

    Thank you, I'll try that today.



    PS: This is a great board, and it's nice to have this kind of resource to turn to.
    Mria

  • #4
    New to the CF scene
    Join Date
    Jul 2003
    Location
    MD, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still have questions

    My body tag currently has a whole preload script in it. Should I place the onload="Countdown()" section before or after the preloaded images (or does this not make a difference?)

    Thank you. (Still testing the script).

    Mria

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    If you already have an onload event in the opening BODY tag then you need to to put in a semicolon between that one and Countdown()


    <BODY onload="preload() ; Countdown()">

  • #6
    New to the CF scene
    Join Date
    Jul 2003
    Location
    MD, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Jscript Redirect

    Hi, this didn't work. I'm using Macromedia Dreamweaver MX to do the coding. Is there no way to incorporate it into my original script?

    No redirection is occurring at all on my test page. (I changed the dates and times for my test. I also made sure that I changed the amount of days for the test.)

    Any other ideas?

    Thank you.
    Mria

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    I have not used Macromedia Dreamweaver MX so I cannot remark on how it incorporates javascript into pages.

    I have posted a zip file containing the page I used to test the script.

    Experiment with this page on its own.

    When you enter the date and time make sure you enter it as




    Target_Date[Target_Date.length] = new Date(year, month,date,hour, minites,seconds)


    Target_Date[Target_Date.length] = new Date(2003,06,11,15,39,01) // target date 1




    Note that the month entry is one less than the actual month number.

    This month (July) = 07 therefore for the script entry July = 06

    I tested the script by putting todays date, the current hour and altering just the minite entries.


    The script redirected to the sites I entered in the "Set_Url" array at the times I entered.

    I did notice in the script I posted above I forgot to take out my test alert but the script should still have redirected.

    See how you go with my test page

  • #8
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Oops forgot the zip

    Attached Files Attached Files

  • #9
    New to the CF scene
    Join Date
    Jul 2003
    Location
    MD, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Redirect

    Ok, I will give it a shot.
    Mria


  •  

    Posting Permissions

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