I am trying to modify my site, using javascript to change background based on weather ( And to finish) Reading problems with font color, as background change works), worked around a simple function:
Function setSessionTheme () {var today = new date ( ); Var First = New Date (Today.Gateful Year (), 0, 1); Var day - year = math (((Today - earlier) / 1000/60/60/24) +5, 0); If (dayYear> = 1 & amp; amp; amp; amp;; & amp;; & lt; 80) {document.getElementById ("mainbg") SetAttribute ('src', "http://www.gfcf14greendream.com/images/winterbg.png"); } If (dairair> = 80 & amp; nbsp; day year & lt; 172) {document.getElementById ("mainbg") setAttribute ('src', "http://www.gfcf14greendream.com/images/springbg.png "); } If (day year => 172 & day year <264) {document.getElementById ("mainbg"). Set Attribute ('src', "http://www.gfcf14greendream.com/images/summerbg.png"); } If (darear> = 264 & amp; day years <355) {document.getElementById ("mainbg") setAttribute ('src', "http://www.gfcf14greendream.com/images/fallbg.png") ; } If (day> = 355 and daywork and lt; = 366) {document.getElementById ("mainbg"). Setitribet ('src', "http://www.gfcf14greendream.com/images/winterbg.png"); }} should change the background of the page according to the day of the year, modify the IMG tag on this div:
& lt; Div id = "background" & gt; & Lt; Img id = "mainbg" src = "http://www.gfcf14greendream.com/images/greentwi.png" square = "section" alt = "" /> & Lt; / Div & gt; But still, the original URL of the image appears, through the function, it should be a source when the debugger receives this line, then document.getElementById (" Mainbg ") set attribute ('src'," http://www.gfcf14greendream.com/images/summerbg.png "); , I get this error: UnkeyType type error: method can not call call 'setAttribute' Why this is Used to be? If the original image is displayed then why should the IMG tag be tagged for background? Thanks to anyone who can provide help or suggestion to me
The 'object' tag in your page Embedded is an html file:
and the script
http://www.gfcf14greendream.com/JS/greendream.js The top HTML and sub-HTML files have been declared and actually one is merged, it is one of the sub-HTML (thesitelog.html's body by the load function).
In the sub html, if you need to use the element in the original html, then you need to use
window.parent.document.getElementById (' Something like 'mainbg') document.getElementById instead of
then a quick Fixed all in the document For main bang like has access to basic access, and you can comment script tags in the top html :
& lt ;! - script type = "text / javascript" src = "http://www.gfcf14greendream.com/JS/greendream.js" & gt; & Lt; / Script - & gt; It should fix your current error.
No comments:
Post a Comment