openXS
08-27-2007, 11:03 AM
Hi,
I've two JS that seem to be conflicting with each other. Just of them works due to the window.onload issue:
First one has "window.onload=function()" and the other one "window.onload=stripe"
Is there anyway I can get both these JS to work correctly in IE/FF/Safari?
Any help greatly appreciated.
Many Thanks.
Steve_Arm
08-27-2007, 11:11 AM
<body onLoad="function()"> ?
openXS
08-27-2007, 11:14 AM
Tried that already, the other JS doesn't work. Should I put up both JS for you to see?
openXS
08-27-2007, 11:16 AM
First:
var stripe=function(){
var tables=document.getElementsByTagName("table")
for(var x=0;x!=tables.length;x++){
var table=tables[x]
if(! table){return;}
var tbodies=table.getElementsByTagName("tbody")
for(var h=0;h<tbodies.length;h++){
var even=true
var trs=tbodies[h].getElementsByTagName("tr")
for(var i=0;i<trs.length;i++){
trs[i].onmouseover=function(){
this.className+=" ruled";return false}
trs[i].onmouseout=function(){
this.className=this.className.replace("ruled","");return false}
if(even)
trs[i].className+=" even"
even=!even}}}}
window.onload=stripe
Second:
window.onload=function(){
if(!NiftyCheck())
return;
Rounded("div#v_content","tr, bl, br","#ffffff","#E8F1F6","smooth");
}
Steve_Arm
08-27-2007, 11:16 AM
Sure. Why not merge them into a single window.onload?
Xenatino
08-27-2007, 06:42 PM
I would recommend either combining them into one function:-
<script type="text/javascript" language="Javascript">
function init()
{
// function stripe()
var tables = document.getElementsByTagName("table");
for (var x=0; x!=tables.length; x++)
{
var table = tables[x];
if (!table)
{
return;
}
var tbodies = table.getElementsByTagName("tbody");
for(var h=0; h<tbodies.length; h++)
{
var even = true;
var trs = tbodies[h].getElementsByTagName("tr");
for (var i=0; i<trs.length; i++)
{
trs[i].onmouseover = function()
{
this.className += " ruled";
return false;
}
trs[i].onmouseout = function()
{
this.className = this.className.replace("ruled","");
return false;
}
if(even)
trs[i].className+=" even";
even = !even;
}
}
}
// function rounded()
if(NiftyCheck())
{
Rounded("div#v_content","tr, bl, br","#ffffff","#E8F1F6","smooth");
}
}
window.onload=init;
</script>Or creating 1 function to call 2 others:-
<script type="text/javascript" language="Javascript">
function stripe()
{
var tables = document.getElementsByTagName("table");
for (var x=0; x!=tables.length; x++)
{
var table = tables[x];
if (!table)
{
return;
}
var tbodies = table.getElementsByTagName("tbody");
for(var h=0; h<tbodies.length; h++)
{
var even = true;
var trs = tbodies[h].getElementsByTagName("tr");
for (var i=0; i<trs.length; i++)
{
trs[i].onmouseover = function()
{
this.className += " ruled";
return false;
}
trs[i].onmouseout = function()
{
this.className = this.className.replace("ruled","");
return false;
}
if(even)
trs[i].className+=" even";
even = !even;
}
}
}
}
function rounded()
{
if(NiftyCheck())
{
Rounded("div#v_content","tr, bl, br","#ffffff","#E8F1F6","smooth");
}
}
function init()
{
strip();
rounded();
}
window.onload=init;
</script>
foobic
08-27-2007, 06:55 PM
Wordpress uses this code to handle multiple onload functions. To use it replace all window.onload=functionname with addLoadEvent(functionname):
<script type="text/javascript">
//<![CDATA[
function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
//]]>
</script>
...
</head>
<body onload="wpOnload()">