PDA

View Full Version : JS Running JS Functions from window.onload



wyclef
May 29th, 2008, 12:35 PM
I'm trying to run these two functions onload and don't want the onload command in the body tag and am wondering if the way I set it up at the bottom is correct. It works fine but i'm not sure it's the right way.


/* ================================================== ==============
This copyright notice must be untouched at all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/menu/paged_menu.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any
way to fit your requirements.
================================================== ================= */

rollMenu = function(menu) {
var getEls = document.getElementById(menu).getElementsByTagName ('LI');
var getAgn = getEls;

for (var i=0; i<getEls.length; i++) {
getEls[i].onmouseover=function() {
for (var x=0; x<getAgn.length; x++) {
getAgn[x].className=getAgn[x].className.replace('roll', '');
}
this.className+=' roll';
}
}
}



//-- ABBR Style, $Revision: 1.0 $,
//-- Courtesy of A List Apart: www.sovavsiti.cz/css/abbr.html

function styleAbbr() {
var oldBodyText, newBodyText, reg
if (isIE) {
oldBodyText = document.body.innerHTML;
reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class=\"abbr\" $1>$2</SPAN></ABBR>');
document.body.innerHTML = newBodyText;
}
}

window.onload = function() {
styleAbbr()
rollMenu('menu')
};

isIE = (document.all) ? true:false;

fasterthanlight™
May 29th, 2008, 12:45 PM
instead of window.onLoad = funtion () { }

I would define a function that calls your two functions normally,

and then call that in your .onLoad

init = function () {
styleAbbr()
rollMenu('menu')
}

window.onLoad = init;


http://javascript.about.com/library/blonload.htm



the way you have it now *should* work me thinks....

sekasi
May 29th, 2008, 01:20 PM
edit: Link had an example that didn't work. tried it :/ removed it. Sori!

wyclef
May 29th, 2008, 04:28 PM
yea, that didnt work

Syous
May 29th, 2008, 04:46 PM
Why can't you have it in the body tag?

wyclef
May 29th, 2008, 06:29 PM
phobia