View Full Version : Site background not showing on iPad

11-09-2011, 04:31 PM
Hi Guy,

Please see our website http://preview.tinyurl.com/7p2zsjt

The background of this site uses javascript to generate the background depending on the time of day and this works perfectly for most browsers tested...

<body onload = "chgbg()">

<script type="text/javascript">

function chgbg() {
var d = new Date();
var h = d.getHours();

if ((h >= 6) && (h < 9)) {document.body.style.backgroundColor = "#FFFFFF"; document.body.style.backgroundImage="url(sunrise.jpg)"}
if ((h >= 9) && (h < 20)) {document.body.style.backgroundColor = "#FFFFFF"; document.body.style.backgroundImage="url(day.jpg)"}
if ((h >= 20) && (h < 22)) {document.body.style.backgroundColor = "#FFFFFF"; document.body.style.backgroundImage="url(sunset.jpg)"}
if ((h >= 22) || (h<6)) {document.body.style.backgroundColor = "#FFFFFF"; document.body.style.backgroundImage="url(night.jpg)"}

window.setTimeout (chgbg, 5000); // update time (hour) every five seconds

Problem is the background does not show when using an iPhone or iPad (I haven't tested on other mobile devices). If the user has javascript switched off (rare I'd have thought) then the day.jpg loads via the css as the background. I am happy to use this image as the iPad background but no matter what I seem to do in the code, I cannot get this to work :(

Any advice will be greatly appreciated. I've been going around in circles with this for quite some time now, but my coding knowledge is limited so I could be missing something simple? I hope...