home *** CD-ROM | disk | FTP | other *** search
/ PC User 2005 May / CD / PCU0505CD.iso / software / full / coffecup / files / html2005.exe / %MAINDIR% / Javascript / Random-images.xml < prev    next >
Encoding:
Text File  |  2005-02-16  |  2.3 KB  |  103 lines

  1. <ccResource>
  2.   <ccTitle>
  3. Random Images
  4.   </ccTitle>
  5.   <ccCategory>
  6. Browser
  7.   </ccCategory>
  8.   <ccDescription>
  9. As an alternative to background colors and random background colors, JavaScript allows you to have random background images.   <ccInstructions>
  10.    1.  Paste the first code into the HEAD of your HTML document
  11.    2.  Add the onLoad event handler to the BODY tag
  12.    3.  Place the last script in the BODY of your HTML document
  13.    4.  Save the 7 background images to your directory 
  14.        </ccInstructions>
  15.   <ccHeadContent>
  16.   
  17.   </ccHeadContent>
  18.   <ccBodyContent>
  19.  
  20. <SCRIPT LANGUAGE="JavaScript">
  21.  
  22.  
  23. today=new Date();
  24. jran=today.getTime();
  25. var number = 7;
  26. var random_number="";
  27. var image="";
  28. var text_color="";
  29. ia=9301;
  30. ic=49297;
  31. im=233280;
  32. jran = (jran*ia+ic) % im;
  33. random_number = Math.ceil( (jran/(im*1.0)) *number);
  34. // Loads the appropriate image and text color based on random number.
  35. if (random_number==1) {
  36. text_color="000000";
  37. image="paper.gif";
  38. }
  39. if (random_number==2) {
  40. text_color="000000";
  41. image="wood.gif";
  42. }
  43. if (random_number==3) {
  44. text_color="000000";
  45. image="clouds.gif";
  46. }
  47. if (random_number==4) {
  48. text_color="000000";
  49. image="faces.gif";
  50. }
  51. if (random_number==5) {
  52. text_color="000000";
  53. image="marble.gif";
  54. }
  55. if (random_number==6) {
  56. text_color="000000";
  57. image="question.gif";
  58. }
  59. if (random_number==7) {
  60. text_color="000000";
  61. image="plain.gif";
  62. }
  63. // End -->
  64. </SCRIPT>
  65. <!-- STEP TWO: Add this onLoad event handler to the BODY tag -->
  66.  
  67. <SCRIPT LANGUAGE="JavaScript">
  68.  
  69. <!-- Begin
  70. document.open();
  71. document.write("<BODY  BACKGROUND='"+image+"' TEXT='"+text_color+"'>");
  72. document.write("<CENTER></CENTER>");
  73. // End -->
  74. </SCRIPT>
  75.  
  76. <!-- STEP THREE:  Place this script in the BODY of the HTML document  -->
  77.  
  78.  
  79. <FORM>
  80. <INPUT  TYPE="button" VALUE="Reload  Page" onClick="window.location='r-images.html'">
  81. </FORM>
  82. <SCRIPT LANGUAGE="JavaScript">
  83. <!-- Begin
  84. document.write("<CENTER>Background Image: <FONT SIZE=-1>("+image+")</FONT></CENTER>");
  85. // End -->
  86. </SCRIPT>
  87.  
  88. <!-- STEP FOUR: Save the 7 background images to your directory -->
  89.  
  90.  
  91.  
  92.  
  93.   </ccBodyContent>
  94.   <ccElementContent>
  95.   
  96.    <ccElementName></ccElementName>
  97.    <ccElementAction></ccElementAction>
  98.    
  99.   </ccElementContent>
  100.   <ccExtraData>
  101.  
  102.   </ccExtraData>
  103. </ccResource>