View Single Post
Old 10-11-2012, 04:51 PM   PM User | #21
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Lightbulb

Quote:
Originally Posted by b0mbardo View Post
I have been searching for this for awhile now. I know this is an older thread but still has relevance. I am sure you have heard it a thousand times but I do not consider myself a coder by any stretch of the term. So here is my questions on the code as it refers to jmrker's post on 6/14/2012. I get how and where to change image refrences to my own and even adjusted the holidays I need and hours. Does this get saved as an external js file? or is it simply pasted before the </head> tag and then utilze <img id="logo" src="" alt=""> to place the image wherever on the page? Sorry if this is a n00b question
My assumption is that you are referring to this bit of code:
Code:
<!DOCTYPE HTML>
<html>
<head>
<title> Logo Script </title>
<script type="text/javascript">
// For: http://www.codingforums.com/showthread.php?p=1101084#post1101084

var logos = [
	'http://www.nova.edu/hpd/otm/pics/4fun/11.jpg',  // on-air image
	'http://www.nova.edu/hpd/otm/pics/4fun/21.jpg',  // off-air image
	'http://www.nova.edu/hpd/otm/pics/4fun/31.jpg'   // holidays image
]; 
var holidays = ['1/1', '2/14', '3/17', '6/6',  '6/14',
		'7/4','10/31','11/24','11/25','12/24','12/25'];

onload = function () {
  var now = new Date();
  var DOW = now.getDay();
  var HH = now.getHours();
  if ( ((HH >= 8) && (HH < 18)) && ((DOW >= 1) && (DOW < 6)) ) {
    document.getElementById('logo').src = logos[0];
  } else {
    document.getElementById('logo').src = logos[1];
  }
  
  var tmp;
  for (var i=0; i<holidays.length; i++) {
	tmp = new Date(holidays[i]+'/'+now.getFullYear());
//	alert(tmp.toDateString()+'\n'+now.toDateString());  // for testing
	if (tmp.toDateString() == now.toDateString()) {
      document.getElementById('logo').src = logos[2];
    }
  }
}
</script>

</head>
<body>
<img id="logo" src="" alt="">
</body>
</html>
The code as it is, is stand-alone. It should work if you save the file and call it with your browser as a file on you local computer or remote server.

Can the JS be moved to an external file? Sure.
Copy code between the <script> and </script> tags and paste it to an accessable location (usually same directory as program).
Do not copy the <script> tags to the external file.
Change the script reference to <script type="text/javascript" src="externalFileName.js"></script>

If it still doesn't work, post the code you are using so we can see what you are doing differently.

Good Luck!
jmrker is offline   Reply With Quote