SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Image display

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2000
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone point me in the direction of a script that will show an image for, let's say, two days and then after that time show another image? I have one which will change images every day of the week but I'm looking for something where the original image never appears again. Possible???

    PS. Complete Javascript idiot - I can only copy and paste!!!

    Thanks!

  2. #2
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm assuming that you're trying not to show the original image after a user has already visited your site and viewed that image? If so, you could use a cookie to see if the visitor has already been to your site. If the cookie is there, display a different image, otherwise write the cookie. Put this script in the head of your page.

    <script language="JavaScript">
    <!--

    if (document.cookie)
    {document.myImageName.src="newImage.gif"}
    else
    {setCookie('myCookie','oatmeal','Thu, 01-Jan-2010 00:00:01 GMT') }

    function setCookie(name,value,expires,path,domain,secure)
    { document.cookie = name + "=" +escape(value) + ( (expires) ? ";expires=" + expires: "") + ( (path) ? ";path=" + path : "") + ( (domain) ? ";domain=" + domain : "") + ( (secure) ? ";secure" : "");
    }

    // -->
    </script>

    In this line of the script:
    {document.myImageName.src="newImage.gif"}

    change 'myImageName to the name of your image (not the src of the image):

    <img name="myImage" src="blah.gif">

    And change 'newImage.gif' to the name of the image that you want displayed if the user has already visited the page.


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
  •