Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

Change background on top by time

Aloittaja gidus, lokakuu 15, 2013, 10:26:51 AP

« edellinen - seuraava »

gidus

The idea is to change background by the clock time if it's morning a background type if it's night another type so:

I added to my css file style the following codes :
.morning { background:url(bg-header.png); }
.night { background:url(bg-headernight.png); }


And i tried to add to index.template.php the following code
<body onload="var hr=new Date().getHours();document.getElementById('wrapper').className = (hr >= 6 && hr < 19 ? 'morning': 'night');">';

But i received an error about wrong syntax how could fix that?

Kindred

you can't use mixed quotes like that...   SMF uses php echo statements with single quotes to display the content... which means that any single quotes MUST be escaped, if used within the echo.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

gidus

So i have to do a javascript function out from body and recall it with body onload="fuctionname()" ??

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

gidus

<body onload=var hr=new Date().getHours();document.getElementById('wrapper').className = (hr >= 6 && hr < 19 ? 'morning': 'night')>';

Like that?

Kindred

#5
no...   you just took out the double quotes, which makes it even worse.

I said that you need to ESCAPE the quotes... like  \'   but I don't know if even that will work correctly.

http://stackoverflow.com/questions/5647242/how-to-escape-quotes-and-already-escaped-quotes-in-php-before-passing-to-javascr
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

As in:
<body onload="var hr=new Date().getHours();document.getElementById(\'wrapper\').className = (hr >= 6 && hr < 19 ? \'morning\': \'night\');">';

(and not escaping the last one because that's the end of the echo statement.
Holder of controversial views, all of which my own.


gidus

It's works but after i loaded it the charcther of forum it's all in Bold Type  :'( like that Test maybe i have to adding something ?

Arantor

Or it was done wrong, but can't tell that without seeing this live.
Holder of controversial views, all of which my own.


Advertisement: