<?xml version="1.0"?>
<rss version="2.0">
 <channel>
  <title>CSS Q: Use a different image on reload? | WPDFD.com Forums</title>
  <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/</link>
  <description>A Markup forum thread at WPDFD.com</description>
  <language>en-us</language>
  <pubDate>10/27/04, 301 07 2004 2004:%i:1098932853 23:07:33</pubDate>
  <lastBuildDate>06/06/13, 157 33 2013 2013:%i:1370576030 23:33:50</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>NineLabs Framework Feed Generator</generator>
  <managingEditor>sitemaster@wpdfd.com</managingEditor>
  <webMaster>sitemaster@wpdfd.com</webMaster>
     <item>
    <title>Schomer  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1468</link>
    <description><![CDATA[Anyone know of a way to have a page display a different image each time the page is reloaded, or maybe change the image each day?<br /><br />I have a header div with a background image, which I would like to have changed periodically. Right now, I do it manually by changing the CSS doc.<br /><br />I would love a script of some sort that would do this for me - where I give it a list of images and it rotates through the list.<br /><br />Thanks in advance for any help.<br /><br />Schomer]]></description>
    <pubDate>10/27/04, 301 07 2004 2004:%i:1098932853 23:07:33</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1468</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1469</link>
    <description><![CDATA[It's very simple to do with JavaScript. You can either document.write the image onto the page at the appropriate place or swap the background image of a div. You can do it on a per load basis with random images or sequential images or changing on a daily basis.<br /><br />It makes things slightly easier if you give the images sequential filenames pic1.jpg, pic2.jpc ...etc and they are all the same pixel dimensions.<br /><br />Here is the script that I use on the WPDFD home page to randomly rotate the banner ads using document.write<br /><br />http://www.wpdfd.com/banrotatedir.js<br /><br />If you want something else, just shout.<br /><br />]]></description>
    <pubDate>10/28/04, 302 26 2004 2004:%i:1098941209 01:26:49</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1469</guid>
   </item>
     <item>
    <title>Schomer  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1470</link>
    <description><![CDATA[Thank you so much for your help!<br /><br />What you explained sounds great - exactly what I'm looking to do (replace a background image in a div). However, I took one look at your script and realized it was way over my head in terms of parsing through all your content to see what it's actually doing.<br /><br />Would it be too much trouble showing me a stripped down version of the script, along with what you put in your HTML/CSS doc to make it work?<br /><br />Right now, I have the basic CSS doc with:<br /><br />#header {<br />...<br />background-image: url (image1.jpg);<br />... }<br /><br />And the standard &quot;div id=&quot;header&quot; in my HTML file.<br /><br />I can name the images anything I want, and they are all the same size.]]></description>
    <pubDate>10/28/04, 302 03 2004 2004:%i:1098943431 02:03:51</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1470</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1471</link>
    <description><![CDATA[This is what you want. Your pictures are named pic1.gif...pic4.gif and in a sub folder called images. You can have as many as you like, just change the number in +rnd(4)+.<br /><br />The rnd(n) function returns a random number between 1 and n and the swapPic() function changes the background picture.<br /><br />Sequential numbers would require you to use coookies so I won't complicate matters.<br /><br /><code>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;<br /> &nbsp; &nbsp; &nbsp; &nbsp;&quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;<br />&lt;html lang=&quot;en&quot;&gt;<br />&lt;head&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;title&gt;Random Pictures&lt;/title&gt;<br /> &nbsp; &nbsp; &nbsp;&lt;style type=&quot;text/css&quot; title=&quot;text/css&quot; media=&quot;all&quot;&gt;<br />&lt;!--<br />#header<br />{<br /> &nbsp; &nbsp; &nbsp;position: absolute;<br /> &nbsp; &nbsp; &nbsp;margin-top: 100px;<br /> &nbsp; &nbsp; &nbsp;margin-left: 100px;<br /> &nbsp; &nbsp; &nbsp;width: 468px;<br /> &nbsp; &nbsp; &nbsp;height: 60px;<br /> &nbsp; &nbsp; &nbsp;background-image: url(images/pic1.gif);<br />}<br />--&gt;<br />&lt;/style&gt;<br />&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;<br />&lt;!--<br />function swapPic()<br /> &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp;if(document.getElementById)<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var thePicture=document.getElementById(&quot;header&quot<img src="/images/emoticons/wink.png" class="smiley" />;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var picPath=&quot;images/pic&quot;+rnd(4)+&quot;.gif&quot;;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;thePicture.style.background=&quot;url(&quot;+picPath+&quot<img src="/images/emoticons/wink.png" class="smiley" />&quot;;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp;<br />function rnd(n)<br /> &nbsp; &nbsp; &nbsp;{<br /> &nbsp; &nbsp; &nbsp;return Math.floor(Math.random() * n) + 1;<br /> &nbsp; &nbsp; &nbsp;}<br /> &nbsp; &nbsp; &nbsp;<br />//--&gt;<br />&lt;/script&gt;<br />&lt;/head&gt;<br />&lt;body onload=&quot;swapPic()&quot;&gt;<br />&lt;div id=&quot;header&quot;&gt;&lt;/div&gt;<br /><br />&lt;/body&gt;<br />&lt;/html&gt;<br /><br /></code>]]></description>
    <pubDate>10/28/04, 302 39 2004 2004:%i:1098956352 05:39:12</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1471</guid>
   </item>
     <item>
    <title>Schomer  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1472</link>
    <description><![CDATA[Okay, WOW! You could not have made that any easier for me!!! I dropped it in, and it worked immediately.<br /><br />THANK YOU THANK YOU THANK YOU]]></description>
    <pubDate>10/28/04, 302 03 2004 2004:%i:1098993786 16:03:06</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1472</guid>
   </item>
     <item>
    <title>Schomer  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1473</link>
    <description><![CDATA[For anyone interested, I did a little write up about this script and put together some sample files for anyone who wants to take a quick look at how it works. It's so easy, my write up is clearly overkill, but here it is:<br /><br />http://www.picturebridge.com/random-image]]></description>
    <pubDate>10/29/04, 303 42 2004 2004:%i:1099075373 14:42:53</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1473</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1474</link>
    <description><![CDATA[Excellent. Now, here's a challenge for you. See if you can work out a way to preload the images so that there is no delay between one and the next <img src="/images/emoticons/smile.png" class="smiley" />]]></description>
    <pubDate>10/29/04, 303 47 2004 2004:%i:1099086437 17:47:17</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1474</guid>
   </item>
     <item>
    <title>Schomer  said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1475</link>
    <description><![CDATA[Holy crap, Batman. Preload a randomly-selected image? That kind of makes my head hurt thinking about it. You're talking to the guy who had to copy-paste your script into my page instead of writing my own! <img src="/images/emoticons/smile.png" class="smiley" /><br /><br />By the way, you mentioned cookies would have to be used to have a script step the user through each image, each time they visit the site. Would that also be the case if we wanted to display a specific image each day of the month, or would something like that not need cookies? For instance, I create 31 images, and it displays whichever one matches the current day of the month...]]></description>
    <pubDate>11/02/04, 307 12 2004 2004:%i:1099440757 19:12:37</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1475</guid>
   </item>
     <item>
    <title>Joe Gillespie said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1476</link>
    <description><![CDATA[<blockquote><strong>schomer said:</strong><br />
Holy crap, Batman. Preload a randomly-selected image? That kind of makes my head hurt thinking about it. You're talking to the guy who had to copy-paste your script into my page instead of writing my own! <img src="/images/emoticons/smile.png" class="smiley" /></blockquote><br /><br />He he. It might sound difficult but it isn't.<br /><br /><blockquote><strong>schomer said:</strong><br />
By the way, you mentioned cookies would have to be used to have a script step the user through each image, each time they visit the site. Would that also be the case if we wanted to display a specific image each day of the month, or would something like that not need cookies? For instance, I create 31 images, and it displays whichever one matches the current day of the month...</blockquote><br /><br />The cookies are only necessary to remember the last image loaded between page visits. To do it on a day by day basis, you can get the number from the Date object.<br /><br />This function will return a number from 1-31 (in months that have 31 days - I'll leave it to you to work out how to handle 28,29,30)<br /><br /><code><br />function day()<br />{<br />var today = new Date();<br />return date.getdate()<br />}</code><br />]]></description>
    <pubDate>11/03/04, 308 12 2004 2004:%i:1099469530 03:12:10</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p1476</guid>
   </item>
     <item>
    <title>T Irwin said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p2534</link>
    <description><![CDATA[I was attempting to use the code you suggested on the page (witha  few personal changes, ie image titles etc) but I cant seem to get it working, is there something I have done wrong?<br />
<br />
~ Tirwin]]></description>
    <pubDate>11/23/08, 328 37 2008 2008:%i:1227454650 10:37:30</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p2534</guid>
   </item>
     <item>
    <title>G. Nowland said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p2660</link>
    <description><![CDATA[This code works FANTASTICALLY!<br />
<br />
There is only <strong>ONE PROBLEM WITH THE CODE</strong>, and it&#39;s not the fault of anyone but the website being too smart for itself.<br />
<br />
In the code above, the website turned a couple of characters into smilies when they should  be parenthesis, and when copied into your favorite HTML editor the parenthesis are now missing...<br />
<ul><br />
<li>after <em>"header"</em> should be a <em>)</em> before the <em>;</em><ul><li>...the <em>close parenthesis</em> should be between the <em>quotation mark</em> and the <em>semicolon</em>...</li></ul></li><br />
<li>after <em>"+picPath+"</em> should be a <em>)</em> before the <em>"</em><ul><li>...the <em>close parenthesis</em> should be between the two <em>quotation marks</em>...</li></ul></li><br />
</ul><br />
fixing this should render a completely working file!!!<br />
<br />
]]></description>
    <pubDate>04/15/09, 105 52 2009 2009:%i:1239821569 14:52:49</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p2660</guid>
   </item>
     <item>
    <title>Serkan Serbest said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p3041</link>
    <description><![CDATA[Thank you so muck <img src="/images/emoticons/smile.png" class="smiley" /><img src="/images/emoticons/smile.png" class="smiley" /> Mr. Gillespie]]></description>
    <pubDate>10/24/09, 297 18 2009 2009:%i:1256429897 20:18:17</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p3041</guid>
   </item>
     <item>
    <title>Andy Quick said:</title>
    <link>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p3122</link>
    <description><![CDATA[Hi All,<br />
<br />
Quick alternative idea for you. IS it possible to do this with html files?<br />
<br />
IF you made a little image and text htm file and had a few of them in a folder would be possible to pick a random one and place on site?]]></description>
    <pubDate>11/05/09, 309 10 2009 2009:%i:1257462615 18:10:15</pubDate>
    <guid>http://www.wpdfd.com/forums/wpdfd/markup/css_q_use_a_different_image_on_reload/#p3122</guid>
   </item>
   </channel>
</rss