| | |
Can't put 2 Javasript working in the same page!
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
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!
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:
Thanks for any help;
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: html Syntax (Toggle Plain Text)
<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;
•
•
•
•
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!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:
html Syntax (Toggle Plain Text)
<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;
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:
<body onload="init();">
(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]
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
Join Date: Nov 2006
Posts: 2
Reputation:
Solved Threads: 0
Hi,
Thanks a lot for your help! I will try that,but I am not very familiar with JS.Hope I can put it to work. Anyway the two JS libs work great,but I've already try to put like this window.onload = function() { $(document).ready(function() { ... }); }; but dosen't work!!I have another idea,include an external file with just the one script,maybe it works.I will work on it and later I post my results.Thanks. :-)
Thanks a lot for your help! I will try that,but I am not very familiar with JS.Hope I can put it to work. Anyway the two JS libs work great,but I've already try to put like this window.onload = function() { $(document).ready(function() { ... }); }; but dosen't work!!I have another idea,include an external file with just the one script,maybe it works.I will work on it and later I post my results.Thanks. :-)
Last edited by procyon; Nov 24th, 2006 at 6:04 am.
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Internet Explorer not working. (Web Browsers)
- Page_Load never called when I browse to my aspx page (ASP.NET)
- Bogus "page cannot be displayed" error on URL http:/// (Viruses, Spyware and other Nasties)
- On Internet Explorer, My Java does not work! (Web Browsers)
- Login issues (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Alert box, then cancel action (Javascript)
- Next Thread: Random CSS Stylesheet selector exists?
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column cookies createrange() css cursor dependent disablefirebug dom download dropdown editor element engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump libcurl math matrixcaptcha media microsoft mimic object onmouseoutdivproblem onreadystatechange parent pdf php player post problem progressbar rated rating regex runtime scroll search security select session shopping size software sql star stars synchronous text textarea unicode validation w3c web website window windowofwords windowsxp wysiwyg xml \n






