Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-23-2012, 01:56 PM   PM User | #16
m30ndo
New Coder

 
Join Date: Aug 2012
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
m30ndo is an unknown quantity at this point
This code you have given me can go directly into the Wordpress HTML area of the page?

,,am I able to add the image banners I have created ie

http://www.briantcomms.co.uk/wp-cont...e_Are_Open.jpg

http://www.briantcomms.co.uk/wp-cont...ed_Banner1.jpg

Rather than just having text 'Welcome to the store'? If so this is BRILLIANT thank you so much, I thought I would have to change the header.php but your way makes its so much easier.

: )
m30ndo is offline   Reply With Quote
Old 09-23-2012, 01:59 PM   PM User | #17
m30ndo
New Coder

 
Join Date: Aug 2012
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
m30ndo is an unknown quantity at this point
can I add the image banners?
m30ndo is offline   Reply With Quote
Old 09-23-2012, 02:00 PM   PM User | #18
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by m30ndo View Post
Thanks for your help Philip, a user from this forum wrote the code for me, I have added it to the header.php was this the wrong thing to do?

I apologise I am very new to coding, I tried simply adding this code to the page within Wordpress but this did not work : (
Simply place the code in an external file (no HTML tags <script> and </script>) on the pages you want it to be active and call it right ahead of the </body> tag.

<script src="myjsfile.js"></script>
</body>


I don't know anything about Wordpress but I have said you can easily replace the text messages by images.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 09-23-2012, 02:06 PM   PM User | #19
m30ndo
New Coder

 
Join Date: Aug 2012
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
m30ndo is an unknown quantity at this point
Thats great but how? Simply by pasting : http://www.briantcomms.co.uk/wp-cont...e_Are_Open.jpg

Where the Welcome to the store text is ?

Thanks again for you help.
m30ndo is offline   Reply With Quote
Old 10-11-2012, 03:28 PM   PM User | #20
b0mbardo
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
b0mbardo is an unknown quantity at this point
Awesome!!

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
b0mbardo is offline   Reply With Quote
Old 10-11-2012, 04:51 PM   PM User | #21
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,799
Thanks: 30
Thanked 462 Times in 456 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
Reply

Bookmarks

Tags
date change, image, javascript, time and date change, time change

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:13 PM.


Advertisement
Log in to turn off these ads.