Jump to content
  • Advertisement
Sign in to follow this  
lack o comments

[web] Where is script tag allowed?

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
I think a script element is allowed almost anywhere.

Popular places to put it are inside head and inside body.

When you use document.write, it will appear at the place in the html where the script element was (or where it was called from).

However, this is not a particularly nice technique, I prefer putting all my client-side javascript in a .js file and using script src="whatever.js"

Ideally I then set up whatever events necessary inside that .js file by using window.onload = function() { do whatever };

Sometime I also use onclick, onchange, onsubmit attributes in the HTML too. But I avoid them if possible (preferring to set the event handlers manually in the javascript startup routine)

Mark

Share this post


Link to post
Share on other sites
To be honest. I'm using scripts very little for dynamic events. It's just that my nature as a programmer inclines me to write re-usable modules whenever possible (READ: I'm lazy and I like making simple task complex ;)

Because all the pages on my site will have an identical navigation menu and page formatting, I thought it would be easier to write a couple parameterized functions to do this automatically. That way, any changes only need to be done once in the script rather than for every page. Does this sound reasonable? Or am I really just making things too complex?

Share this post


Link to post
Share on other sites
Quote:
Because all the pages on my site will have an identical navigation menu and page formatting, I thought it would be easier to write a couple parameterized functions to do this automatically. That way, any changes only need to be done once in the script rather than for every page. Does this sound reasonable? Or am I really just making things too complex?
It's usually a better idea to handle that server-side. Search engine crawlers ignore javascript, so they won't be able to navigate your site.

Share this post


Link to post
Share on other sites
Ah, thanks for that tip. I'll keep it in mind for the future. For now I won't worry because I don't really expect or nor want a lot of traffic. And even when you don't bother registering with search engines you can expect those google-bots to find you eventually.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!