/    Sign up×
Community /Pin to ProfileBookmark

need HELP! javascript doesn’t work after post on hosting

I want to make a background image change according by the time of day! it works perfectly when I preview locally on my computer. But it does’t work after I uploaded on my web hosting. can anyone solve my problem????
this is my javascript & html code.

[code=html]<body>
<script type=”text/javascript”>

var d = new Date()
var h = d.getHours()

//
if (h < 6) document.write(‘<style type=”text/css”>body {background:#47643a url(http://file.qooza.hk/userfile/8/1/16481/morning.jpg) repeat-x}”></style>’)
else if (h < 17) document.write(‘<style type=”text/css”>body {background:#47643a url(http://file.qooza.hk/userfile/8/1/16481/bodyNewbg.jpg) repeat-x}”></style>’)
else if (h < 20) document.write(‘<style type=”text/css”>body {background:#47643a url(http://file.qooza.hk/userfile/8/1/16481/midnight.jpg) repeat-x}”></style>’)
else if (h < 24) document.write(‘<style type=”text/css”>body {background:#47643a url(http://file.qooza.hk/userfile/8/1/16481/night.jpg) repeat-x}”></style>’)
//–>
</script>
</body>
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@bionoidJan 24.2012 — Writing a <style> tag in the body will not always work:

Try this:

[CODE]<body>
<script type="text/javascript">

var h = new Date().getHours(), s = document.body.style;
if (h < 6) {s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/morning.jpg) repeat-x'; } else
if (h < 17) {s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/bodyNewbg.jpg) repeat-x';} else
if (h < 20) {s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/midnight.jpg) repeat-x'; } else
{s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/night.jpg) repeat-x'; }

</script>
</body>[/CODE]
Copy linkTweet thisAlerts:
@lisa2999authorJan 25.2012 — Writing a <style> tag in the body will not always work:

Try this:

[CODE]<body>
<script type="text/javascript">

var h = new Date().getHours(), s = document.body.style;
if (h < 6) {s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/morning.jpg) repeat-x'; } else
if (h < 17) {s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/bodyNewbg.jpg) repeat-x';} else
if (h < 20) {s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/midnight.jpg) repeat-x'; } else
{s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/night.jpg) repeat-x'; }

</script>
</body>[/CODE]
[/QUOTE]



nope....it works on my computer, but it doesn't work when I upload to the hosting.
Copy linkTweet thisAlerts:
@bionoidJan 25.2012 — HTML is HTML irrespective of its location.

It is more than possible you are receiving a cached version of the page from the host. The next time you view the page please press CTRL+F5, or however the browser you use does it, to download an uncached copy.

Failing that, please provide a link to the uploaded file so we can better determine the cause of the problem.
Copy linkTweet thisAlerts:
@007JulienJan 25.2012 — Are you sure of your path ? Your images are on the good directory on the server ? What does not work ? You have no images ? The image don't change ?

To force the change add a new date.getTime() after a question tag at the end of the address like this (be lazy for short code).
[CODE]<script type="text/javascript">
var h = new Date().getHours(), f, g=new Date().getTime(), s = document.body.style;
if (h < 6) f = 'morning.jpg';
else if (h < 17) f = 'bodyNewbg.jpg';
else if (h < 20) f = 'midnight.jpg';
else f = 'night.jpg';

s.background = '#47643a url(http://file.qooza.hk/userfile/8/1/16481/'+f+'?'+g+') repeat-x';
</script>[/CODE]
×

Success!

Help @lisa2999 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...