/    Sign up×
Community /Pin to ProfileBookmark

JavaScript "OnLoad()" in Body Tag

?I have a javascript that requires “OnLoad()” witin the Body tag. When I cheked the page in W3C Validator, it pointed this out as an error.

Can anyone help me with how to handle this.

My page is using XHTML 1.0 Transitional DOCTYPE.

Thanks
Here4hlp

to post a comment
CSS

7 Comments(s)

Copy linkTweet thisAlerts:
@bejitto101Nov 12.2008 — You need remove it from your body tag. If you body tag looks like: <body onload="init()"> in you javascript file, instead use "document.onload = init;" Keep in mind, don't add the ()'s.
Copy linkTweet thisAlerts:
@Here4hlpauthorNov 12.2008 — Thanks, but I am kind of a bit confused. Where in my document should I place the "document.onload = init;"?

Here4hlp

www.gedochin.com
Copy linkTweet thisAlerts:
@felgallNov 12.2008 — You put it in the JavaScript file that is attached to the had of your page along with the rest of your JavaScript.
Copy linkTweet thisAlerts:
@Here4hlpauthorNov 13.2008 — Thanks once again. I have tried and it does not seem to work.

Following is my script file code:

adImages1 = new Array("graphics/calbanner1.gif","graphics/calbanner2.gif","graphics/calbanner3.gif","graphics/calbanner4.gif")

adImages2 = new Array("graphics/liveworkstudy.jpg","graphics/liveworkstudy1.jpg")

thisAd1 = 0

thisAd2 = 0

imgCt1 = adImages1.length

imgCt2 = adImages2.length

function rotate() {
if (document.images) {
thisAd1++
if (thisAd1 == imgCt1) {
thisAd1 = 0
}
document.adBanner1.src=adImages1[thisAd1]

thisAd2++
if (thisAd2 == imgCt2) {
thisAd2 = 0
}
document.adBanner2.src=adImages2[thisAd2]

setTimeout("rotate()", 3 * 1000)
}
}

function newWindow0() {
cal1Window = window.open("http://gedo.com/", "cal1Win","width=500,height=300,top=10,left=10,resizable=yes")
}

function newWindow1() {
cal2Window = window.open("http://www.myprogram.com/")
}


Where am I to put the "document.onload = rotate"?

Here4hlp
Copy linkTweet thisAlerts:
@felgallNov 13.2008 — adImages1 = new Array("graphics/calbanner1.gif","graphics/calbanner2.gif","graphics/calbanner3.gif","graphics/calbanner4.gif")
adImages2 = new Array("graphics/liveworkstudy.jpg","graphics/liveworkstudy1.jpg")
thisAd1 = 0
thisAd2 = 0
imgCt1 = adImages1.length
imgCt2 = adImages2.length

function rotate() {
if (document.images) {
thisAd1++
if (thisAd1 == imgCt1) {
thisAd1 = 0
}
document.adBanner1.src=adImages1[thisAd1]

thisAd2++
if (thisAd2 == imgCt2) {
thisAd2 = 0
}
document.adBanner2.src=adImages2[thisAd2]

setTimeout("rotate()", 3 * 1000)
}
}

function newWindow0() {
cal1Window = window.open("http://gedo.com/", "cal1Win","width=500,height=300,top=10,left=10,resizable=yes")
}

function newWindow1() {
cal2Window = window.open("http://www.myprogram.com/")
}

window.onload = rotate;
Copy linkTweet thisAlerts:
@Here4hlpauthorNov 14.2008 — Thanks a millioin felgall; you've saved me sleepless nights. It wasn't working because the first respondent had suggested "document.onload= rotate" instead.

Kindest regards,

Here4hlp
Copy linkTweet thisAlerts:
@aj77Nov 28.2008 — is this by any chance related to the idea of a page loading a different image each time the page loads, with the images going in an ordered sequence?

Desperate to find how this is done! This seems related but I can't join it up! Any code?
×

Success!

Help @Here4hlp 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...