| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| DesignersTalk > Unobtrusive JS Question - window.onload external JS files? |
|
LinkBack | Thread Tools | Search this Thread |
|
|
#1 (permalink) |
|
Senior Member
Join Date: Oct 2006
Posts: 2,076
|
Unobtrusive JS Question - window.onload external JS files?
I'm not too clued up on Javascript, so I tend to use 3rd party stuff like SWFObject. At the moment I just dump all these scripts into my "library.js" file, then use the <body onload="function1();function2();"> for the ones that need it. This isnt a particularly good way of going about things, so was hoping to clean up the process a little. Was thinking if it is possible to have a .js file that I link from the head of my xhtml pages, which will then load up all the other .js files - so that way I only have to use the one line in the head to load up all my scripts. Also would be useful to keep them separate, so I can add or remove scripts and upgrade any .js files with newer versions as they get released. And also, possibly unload them too when the page changes, or when they leave the site, or when they close the window - as the google maps api recommends it to prevent memory leaks. Any help, or links most appreciated. |
|
|
|
|
|
#2 (permalink) |
|
Senior Member
Join Date: Oct 2006
Posts: 2,076
|
http://adactio.com/atmedia2005/ Code:
Doing this at the moment, but means I have to have all my scripts in the one library.js file. If anyone can come back with any answers to the original question id be most greatful. |
|
|
|
#4 (permalink) | |
|
WHOA!
Join Date: Jun 2005
Location: Toronto, Canada
Posts: 61
|
Quote:
Yep... I agree. Have one file called global.js or base.js with functions you'll probably use a lot. My first recommendation would be adding addEvent to that file. See http://www.dustindiaz.com/top-ten-javascript/ for more info. Using addEvent is simple so you can forget about body onLoad crap: Code:
|
|
|
![]() |