www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27

Thread: Swap image on site every Monday

  1. #16
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,154
    The difference is minimal 007Julien, whats important is that on odd weeks one image shows and on even weeks another image shows.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  2. #17
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,154
    And theirs that day light savings thing, something that you do not account for, that has been taken care of in the computer for those machines that observe daylight savings, so any script that "Accounts" for day light savings in calculations is only compounding the time shift further from the correct time.

    I asked Microsoft about, short answer is the time that JavaScript uses is based on the system clock, the system clock bases its time on what the system time was set to and it only looks at the clock ticks not the BIOS time that delivers the time base to the system, any sync with external references like atomic clocks is purely operating system based.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #18
    Join Date
    Oct 2013
    Posts
    9
    Quote Originally Posted by \\.\ View Post
    I have tested this in my local web browser.
    What a dramatic change from the original script I had working (after a fashion). I wonder what it is I'm doing wrong as trying the new script still stubbornly refuses to change image colour.


    tech_soul8 - Thanks for trying to help, but I can't get your suggestion to work either - but thanks for trying.

    007Julien - My thanks to you as well but I'm not quite sure what I have to do to incorporate your idea. I have tried it and I got the alerts which changed when the date changed.

  4. #19
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    What minimal difference ? The result may differ a week !
    The computer should be an exact science. It would be better to give reliable results ...

  5. #20
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,154
    we are talking about 0.25 of a day which is 6 hours.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  6. #21
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,154
    Quote Originally Posted by grajay155 View Post
    What a dramatic change from the original script I had working (after a fashion). I wonder what it is I'm doing wrong as trying the new script still stubbornly refuses to change image colour.


    tech_soul8 - Thanks for trying to help, but I can't get your suggestion to work either - but thanks for trying.

    007Julien - My thanks to you as well but I'm not quite sure what I have to do to incorporate your idea. I have tried it and I got the alerts which changed when the date changed.
    If the thing is not working then that means that one of the other scripts is causing a problem as I found when I removed all the other guff in your site, the change worked perfectly.

    The only thing that I can suggest is to have a PHP script set the image.

    PHP Code:
    <?
        $wk 
    date("W"); // get the current week
        
    $colour = ( $wk )? "green.jpg" "black.jpg"
        echo 
    "<img title='' src='images/{$colour}' />";
    ?>
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  7. #22
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    242
    If I have understood you correctly all you want is to get images swapped on each Sunday midnight/Monday morning respectively. So it doesn't really mater if your code misses a week or two or even three... The most important thing is to get first Monday at the start of the year and then start counting weeks from it. With this approach you probably won't get exactly correct number of weeks since the start of the year but it doesn't matter, or it does? All you care about is to get images swapped correctly on each Sunday midnight/Monday morning.

    So I have provided you with the code that does exactly what's stated above. It finds the first Monday at the start of the year and starts to count weeks from there. You get your images swapped according to the fact that you'll have even and odd number of weeks through the year so there's no need for huge list of array elements. Daylight savings also should not cause any troubles because script get's time from the user's local computer. If he/she has not correctly set it up you cannot do anything about it. If you want to influence on that you'll have to use server-side script and get your time from the server.


    If anything from said above is not correct then please feel free to correct me.

    You should incorporate the code in your web document at the following section like this:

    Code:
    <table class="aside_recycle"><tbody><tr><td class="aside_header">THIS WEEK</td></tr><tr><td class="aside_content"><div id="myimagediv"><img src="images/green.png" id="myimage" alt=""></div>
    
    <script type="text/javascript">
    var images = ["images/green.png","images/black.png"];
    var date = new Date();
    //date.setDate()
    var date2 = new Date(date.getFullYear(),0,1) 
    var elem = document.getElementById('myimage');
    		
    while (date2.getDay() != 1)
    {
    	date2.setDate(date2.getDate() + 1)
    }
    		
    var weekNo = Math.floor((date - date2) /1000/60/60/24/7);
    		
    (weekNo % 2 == 0) ? elem.src = images[0] : elem.src = images[1];
    </script></td></tr></tbody></table>
    This is tested and all works very well. You should also check that the "black.png" image is actually located on a server and if it is make sure it is in the correct folder. If you have administrative access to the server you can try to change the date to let's say eleventh of November for example and the image should get swapped.

    If you don't have administrative access to the server you could change the following line of code to influence on a week number:

    Code:
    //date.setDate()
    Put the date number inside of parentheses to shift back or forward in time.

  8. #23
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    242
    Sorry \\.\ I didn't see that you have already replied.

  9. #24
    Join Date
    Oct 2013
    Posts
    9
    Quote Originally Posted by tech_soul8 View Post
    If I have understood you correctly all you want is to get images swapped on each Sunday midnight/Monday morning respectively. So it doesn't really mater if your code misses a week or two or even three... The most important thing is to get first Monday at the start of the year and then start counting weeks from it. With this approach you probably won't get exactly correct number of weeks since the start of the year but it doesn't matter, or it does? All you care about is to get images swapped correctly on each Sunday midnight/Monday morning.

    So I have provided you with the code that does exactly what's stated above.
    And, as you say THAT worked exactly and does what I want. Thank you so much and also thanks too to others who have chipped in. I can see I need to read a good book on Javascript and start working things out for myself.

    Thanks again, I am most grateful.

    Graham

  10. #25
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    242
    You're welcome. Now when I visit your web page I want to see that green/black bin

  11. #26
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    I was speaking about getISONumber scripts !

    Otherwise I agree. Display the wrong color for an image one hour per year is not a serious drawback !

    The ideal would also to make more substantial changes... What about a newspaper with a unique front page !

  12. #27
    Join Date
    Oct 2013
    Posts
    9
    Quote Originally Posted by tech_soul8 View Post
    You're welcome. Now when I visit your web page I want to see that green/black bin
    It's there working like a beauty - thanks again.

Thread Information

Users Browsing this Thread

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

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