/    Sign up×
Community /Pin to ProfileBookmark

Where to place script code? Before, after body tag?

I’ve been experiencing intermittent problems with my web-based application, which uses simple Javascript. Currently, all my <script></script> code is placed at the bottom of my web page, after the </html> tag. Every so often, if I click on a button or link that uses the script code, I get an error “Object excepted”. The error never seems to make sense because I haven’t altered the script code in weeks. I took a closer look at the source of the page and I noticed that the source ended just before my script code! It seemed as though the browser just stopped parsing and did not read the page further. A very strange problem because, like I said, it doesn’t always occur.

Anyway, where is the best place for script code on a page? Inside the html tags? Before the body? After, …?

Thanks,

SAFX

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJul 23.2003 — [font=georgia]Your script is a part of the HTML and as such it has to follow the HTML rules. It needs to be somewhere inside of either the HEAD or BODY elements.[/font]
Copy linkTweet thisAlerts:
@SAFXauthorJul 23.2003 — Thanks!
×

Success!

Help @SAFX spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...