Computing.Net > Forums > Programming > .js in head only?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

.js in head only?

Reply to Message Icon

Name: Yisrael Harris
Date: September 17, 2002 at 09:20:23 Pacific
OS: XP
CPU/Ram: ?
Comment:

I had a javascript section at the end of my file, after the close of the body tag, which fills the innerHTML of one of my tags with a table. The code was working perfectly fine.

But then I wanted to move the script to a separate .js file, because I didn't want it accessible.

When I did so, the code simply stopped working.

I then moved the code inside the head, and got an error. I understand this: since the code was now before the body, I was attempting to access an object which had not yet been created.

So I put all the code inside a function and in the body statement, I put onload= followed by a call to that function.

The code is now working again.

The problem: Since the code is now not called until after all the .gifs are loaded, the page looks frightful until then.

So the types of solutions I'm looking for:
1. Is there an event earlier than onload?
2. Is there any way to refer to a .js file other than from the head?
3. Is there a way to create and fill an object before body?

Anyone responses from someone who understands this problem and has a solution (any off-topic comments and/or questions will be ignored) would be welcome.

Thank you.



Sponsored Link
Ads by Google

Response Number 1
Name: Tom
Date: September 17, 2002 at 16:08:31 Pacific
Reply:

> 2. Is there any way to refer to a .js
> file other than from the head?

Couldn't you just put:
[script src="script.js"][/script]
in place of the script?


0

Response Number 2
Name: Paul Robotham
Date: September 19, 2002 at 01:34:28 Pacific
Reply:

Try the above. Also, you may want to consider preloading your images. This can be done quite easily with JavaScript.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


telnet automation problems with lu and li



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: .js in head only?

website-Refresh goes to home page www.computing.net/answers/programming/websiterefresh-goes-to-home-page/8223.html

FileList control in Javascript??? www.computing.net/answers/programming/filelist-control-in-javascript/474.html

PHP/MySQL problem www.computing.net/answers/programming/phpmysql-problem/11622.html