So, its been a long time since I've been on this site, but I've been lurking again recently and now have a question....
I've never really made a website before, but now I've been tasked with making a webpage that does various things with javascript.
I was wondering what the best approach to laying it all out would be? I've gathered that its a good idea to wrap up the code in functions, and put them in the head, but then some javascript was dependent on the html rendering first, I think document.getElement is..?
at the moment the majority of the code is at the bottom of the page, but its getting messy.
I'm aware this question is slightly open ended, I'm just looking for some good practices and habits. I can code quite well in other languages, not used to this mixing of them on the same page though
5 replies to this topic
#1
Posted 12 July 2011 - 11:49 PM
|
|
|
#2
Posted 13 July 2011 - 02:58 AM
What I usually do (mind you it may not be the best way to do things) is keep all functions and stuff on a separate scripts.js which I then link to the html document on the header.
I never put "loose" scripts on the page. I always tie a javascript action to an event such as body.onload for actions to perform as soon as the page loads or element.onclick for when you click on a certain element.
I never put "loose" scripts on the page. I always tie a javascript action to an event such as body.onload for actions to perform as soon as the page loads or element.onclick for when you click on a certain element.
#3
Posted 13 July 2011 - 04:12 AM
If you wrap all the logic in functions, then you can trigger calling them based on the document rendering being complete. The onload event in <body> is usually a good option.
#4
Posted 13 July 2011 - 06:47 AM
Thanks for the replies. I have been considering seperate js files, will probably have to start using them when I gather enough code. Ah thanks for that wingedPanther, I shall use that. I have now also included some vbscript, mostly because I have to, which is a total pain in the arse
#5
Posted 13 July 2011 - 09:05 AM
Fair warning: vbscript only runs in IE, not any other browser. You would do well to avoid it for client-side scripting.
#6
Posted 13 July 2011 - 11:38 PM
yeah unfortunately thats why I have to use it, I'm trying to test for active X plugins, not easy when there doesn't seem to be a list of the object names anywhere. But thats what I've come to expect from anything IE related. In FF I can just access the navigator array, I hope its that simple in chrome and safari. Its also the first time I've really used a basic language, I didn't realize just how different they are, things like & being used to concatenate strings instead of +.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









