I am working on a website and I dont know much of Javascript,but I need to put to work different scripts on the page,and it wont work!:sad: I've already try to chage all that I remeber to chage,but dosen't work!What I am doing wrong?Can anybody help me out? Here is my code:
<script type="text/javascript" src="/js/mootools.js" ></script> <script type="text/javascript" src="/js/slimbox.js"></script> <script type="text/javascript"> window.onload = function() { // Pick your classes var myBox = document.getElementsByClassName('box_title'); var myBoxOpen = document.getElementsByClassName('information'); // Create the accordion var myAccordion = new fx.Accordion( myBox, myBoxOpen, { onActive: function(tog){ tog.setStyles({color: '#fff', background: '#840000'}); }, onBackground: function(tog){ tog.setStyles({color: '#b7d30b', background: '#7d8c87'}); }, alwaysHide: true } ); } function MM_callJS(jsStr) { //v2.0 return eval(jsStr) } </script> <script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript" src="/js/innerfade.js"></script> <script type="text/javascript"> $(document).ready( function(){ $('ul#hFade').innerfade({ speed: 7000, timeout: 13000, type: 'sequence', containerheight: 'auto' }); }); </script>Thanks for any help; :)
Hi,
It looks like you're using two JS libs, mootools and jquery. I haven't used either but from what you explained I noticed:
$(document).ready(function() { ... });
and
window.onload = function() { ... };
are probably the same thing...
So the second one to be executed would overwrite the first as the window.onload function.
If you want to execute multiple functions on window load you may want to use a funciton like:
[HTML]
window.multi_onload = function(func) {
if (typeof(window.onload) == 'function') {
var load = window.onload;
window.onload = function() {
load();
func();
};
} else {
window.onload = func;
}
};
[/HTML]
This would still fall short if someone were to use html like:
(I believe) since "init();" would have the type "string".
for this maybe a try/catch statement around an eval() of the old window.onload of type "string" would work....Untested:
[HTML]
window.multi_onload = function(func) {
if (typeof(window.onload) == 'function') {
var load = window.onload;
window.onload = function() {
load();
func();
};
} else if (typeof(window.onload) == 'string') {
var load = window.onload;
window.onload = function() {
try {
eval(load);
func();
} catch(e) {
/* trap error */
}
};
} else {
window.onload = func;
}
};
[/HTML]