Web Analytics Made Easy -
StatCounter code to run script on a given date? - CodingForum

Announcement

Collapse
No announcement yet.

code to run script on a given date?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • code to run script on a given date?

    Hey ya'll,

    I currently am using a PVII script on my page.
    It runs using this...

    <body onload="P7AniMagic('JS',200,0,10,30,1,1000)">

    Now what this does is move a layer 200px after a delay of 1 sec.
    What I'd like to do is...

    setup a javascript that says

    onload...

    if date is 26,10,2006 run "P7AniMagic('JS',100,0,10,30,1,1000)"

    else if date is 28,10,2006 run "P7AniMagic('JS',120,0,10,30,1,1000)"

    else if date is 30,10,2006 run "P7AniMagic('JS',140,0,10,30,1,1000)"

    Can some kind soul show me how to create such a code - I'm just not up to par on js yet!

    Thank you!

  • #2
    Here you go.

    PHP Code:
    <html>
    <
    head>
    <
    title>Launch on Date</title>
    <
    script type="text/javascript"><!--
    function 
    testDate(){
        var 
    d=new Date();
        
    d=d.getDate()+","+(d.getMonth()+1)+","+d.getFullYear();
        var 
    dates=[
            [
    "26,10,2006",function(){P7AniMagic('JS',100,0,10,30,1,1000)}],
            [
    "28,10,2006",function(){P7AniMagic('JS',120,0,10,30,1,1000)}],
            [
    "30,10,2006",function(){P7AniMagic('JS',140,0,10,30,1,1000)}]
            ];
        for (var 
    i=dates.length-1;i>-1;i--)if (d==dates[i][0])dates[i][1]();
    }
    //--></script>
    </head>
    <
    body onload="testDate()">
    </
    body>
    </
    html
    Note: This will run the P7AniMagic only on the 26th, 28th and 30th... not on 27th or 29th... Is that what you wanted?

    Comment


    • #3
      VortexCortex ur an absolute star!

      I changed the first date to

      Code:
      ["5,10,2006",function(){P7AniMagic('JS',100,0,10,30,1,1000)}],
      to see if it moved today and it did!

      P.S. Yes I only wanted it to run on certain days..

      Shame there's no rating system here! U'd get 5 from me!
      Last edited by dommy; Oct 5, 2006, 07:12 PM.

      Comment


      • #4
        LOL, I knew you'ld be back for a range of days.

        Originally posted by dommy via PM
        Hi VortexCortex,
        If date is between 25,10,2006 and 30,10,2006 then run run "P7AniMagic('JS',100,0,10,30,1,1000)"
        you could just add more date lines to the prevoius code...
        Code:
        ["23,10,2006",function(){P7AniMagic('JS',100,0,10,30,1,1000)}],
        ["24,10,2006",function(){P7AniMagic('JS',100,0,10,30,1,1000)}],
        ["25,10,2006",function(){P7AniMagic('JS',100,0,10,30,1,1000)}],
        ["26,10,2006",function(){P7AniMagic('JS',100,0,10,30,1,1000)}],
        ["28,10,2006",function(){P7AniMagic('JS',120,0,10,30,1,1000)}],
        ["30,10,2006",function(){P7AniMagic('JS',140,0,10,30,1,1000)}]
        Notice: the last one does not have a comma "," at the end of the line.

        Or you could rewrite the code to test for a range between two dates.
        Code:
        <html>
        <head>
        <title>Launch on Date</title>
        <script type="text/javascript"><!--
        function testDate(){
            var d=new Date();
            var dates=[
                [[26,10,2006],[27,10,2006],function(){P7AniMagic('JS',100,0,10,30,1,1000)}],
                [[28,10,2006],[29,10,2006],function(){P7AniMagic('JS',120,0,10,30,1,1000)}],
                [[30,10,2006],[31,10,2006],function(){P7AniMagic('JS',140,0,10,30,1,1000)}]
                ];
        	function inRange(){
        		var x = new Array();
        		for(var i=0;i<2;i++){
        			x[i] = arguments[i];
        			x[i] = new Date(x[i][2],x[i][1]-1,x[i][0]);
        			if(i>0)x[i].setHours(23,59,59,999);
        		}
        		return ((d.getTime() >= x[0].getTime()) && (d.getTime() <= x[1].getTime()));
        	}
        	var doWork=function(){};
            for (var i=0;i<dates.length;i++)if (inRange(dates[i][0],dates[i][1]))doWork=dates[i][2];
        	doWork();
        }
        //--></script>
        </head>
        <body onload="testDate()">
        </body>
        </html>
        You can add more date tests to this code as well...
        In The above code: if today lies between two different ranges, only the last range specified in the list has its p7AniMagic called...

        So, if you want the whole month to use one p7aniMagic, and use another for the 2nd thru 6th, and use nothing at all on the 4th use dates ranges like this:
        Code:
            var dates=[
                [[1,10,2006],[31,10,2006],function(){P7AniMagic('JS',100,0,10,30,1,1000)}],
                [[2,10,2006],[6,10,2006],function(){P7AniMagic('JS',120,0,10,30,1,1000)}],
                [[4,10,2006],[4,10,2006],function(){;}]
                ];
        Note... you can put whatever code you want between the { } in "funciton{p7AniMagic...}" and the code will get executed.
        function{alert('Hi!');} would work bring up an alert box..
        function{window.top.location="http://www.somewhere.com";}
        would redirect to another page.

        PM me if you need more help with this code.

        Comment


        • #5
          Thanks VortexCortex... I'll have a test with this tonight. I gathered the simple way would have been to write out each date.. but when the code needs to run over 5 months - the code would get too heavy.

          I'll post back tomorrow - cheers mate!
          P.S. Check the nominate thread - ur in there!
          P.S.S. PM me ur msn/yahoo etc IM email - would love to have u in there!.. maybe you could help with another problem I've been having. lol.

          Comment


          • #6
            You can add to VortexCortex's reputation by clicking the scale icon in the bottom left of the post.

            If you PM each other no one else will be able to follow this thread
            The silent one.

            The most dangerous thing in the world is an idea.
            The most dangerous person in the world is the one with an idea.

            Comment


            • #7
              Mr J - The entire thread discussion is here - right up to the fix. I just wanted his personal IM for the future...

              Comment

              Working...
              X