...

View Full Version : Multiple scripts conflict?



bubulac
05-27-2012, 07:26 PM
Hello everybody,
I hope I can get some help here with a possible script conflict.
I have a script for a popup calendar (http://www.epoch-calendar.com/javascript_calendar/index.html) that requires the following initialization:



<script type="text/javascript">
var calendar1; /*must be declared in global scope*/
/*put the calendar initializations in the window's onload() method*/
window.onload = function() {
calendar1 = new Epoch('today','popup',document.getElementById('today'),false);
calendar2 = new Epoch('LMP1','popup',document.getElementById('LMP1'),false);
};
</script>


It works well as long as the <body> tag doesn't have any other onload functions added.

However, if I try to add other scripts (freehand drawing, etc) that would make the <body> tag look like this:


<body onload="init(); ReloadImage(); SetSwitchOn('Freehand'); checkIt();">


nothing works anymore, neither the calendar nor the other functions.
Any suggestions?...
Thank you in advance.

chump2877
05-27-2012, 07:35 PM
The DOM 'window' can only have one onload event handler...So you'll need to combine all of your onload event code into a singe event handler.

In your case:


<body>
<script type="text/javascript">
var calendar1; /*must be declared in global scope*/
/*put the calendar initializations in the window's onload() method*/
window.onload = function() {
init();
ReloadImage();
SetSwitchOn('Freehand');
checkIt();
calendar1 = new Epoch('today','popup',document.getElementById('today'),false);
calendar2 = new Epoch('LMP1','popup',document.getElementById('LMP1'),false);
};
</script>

See this link (http://stackoverflow.com/questions/191157/window-onload-vs-body-onload)...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum