Webpages and JavaScript

S

SmilingPolitely

I have a couple of questions on the use of JavaScript in web pages, that
I would like to open to the forum to discuss...

What are the pros and cons when using JavaScript as a substitute for
<include> for information contained on every page?

e.g.

I have a header in a .js file on every page of my site:
document.write("<a href=\"index.html\">Home<\/a> | ");
document.write("<a href=\"about.html\">About<\/a> | ");
document.write("<a href=\"bio.html\">Biography<\/a> | ");


called by:

<script type="text/javascript" src="header.js"></script>

There has been some discussion around about the use of javascript to do
this, specifically for those browsers and/users that are not JavaScript
enabled.....

but the next problem,

if the browser is not JavaScript enabled and therefore unable to see my
..js headers and footers, then how can I expect them to fill in a form
that is validated using JavaScript?

Is there a way to account for all users and their browsers, or do I aim
somewhere in the middle, html headers and footers but with JavaScript
form validation?


For your consideration.


Scott
 
M

mbstevens

SmilingPolitely said:
if the browser is not JavaScript enabled and therefore unable to see my
.js headers and footers, then how can I expect them to fill in a form
that is validated using JavaScript?

JavaScript is fine for checking forms client side, but you always need
to do taint checking and further validation server side. Crackers can
easily subvert client side checks.

The client side checks will save a few moments for visitors who have
JavaScript enabled, which is one of the good uses for that technology.

Is there a way to account for all users and their browsers, or do I aim
somewhere in the middle, html headers and footers but with JavaScript
form validation?

Yes, use server side programming. Perl/CGI (my favorite) or PHP are
common. A few services are also starting to support Python and Ruby.
There are also some monopolized solutions from Mordor$oft, whose names I
shall not utter here. <dog howls in the background> For headers and
footers that repeat on each page, you can use a preprocessor, generate
the pages server side, or use SSI (which is also a way of generating
pages server side).

I believe that many people avoid server side solutions because they
think it will somehow be too hard (it's not), or they don't have
privileges on their host. I can only say -- get a host that allows you
to do server side programming, and start collecting information on
server side programming.
 
D

David Dorward

SmilingPolitely said:
I have a couple of questions on the use of JavaScript
in web pages, that I would like to open to the forum
to discuss...
What are the pros and cons when using JavaScript
as a substitute for <include> for information
contained on every page?

Pro. You can skimp on your server.
Con. User agents without JavaScript (such as GoogleBot, Lynx and
whatever browser came with my cellphone) won't get the data.
if the browser is not JavaScript enabled
and therefore unable to see my .js headers
and footers, then how can I expect them to
fill in a form that is validated using
JavaScript?

You can't. You should only use JavaScript to make things more
convenient[1] (or perhaps more fun) for users. When it comes to
ensuring information is available, and sanity checking data the user
provides then you MUST do that on the server.

[1] "Oh, you didn't fill in an email address, the server's going to
reject this anyway so I'll save you the round trip" does qualify.
 
R

rf

SmilingPolitely said:
What are the pros and cons when using JavaScript as a substitute for
<include> for information contained on every page?

Javascript should *add* to a page, not be part of it.
document.write("<a href=\"index.html\">Home<\/a> | ");

This is navigation. Navigation should *never* be done with javascript. Why
exclude 10% of your viewers and, more importantly, the search engine bots.
 
T

Travis Newbury

SmilingPolitely said:
I have a couple of questions on the use of JavaScript in web pages, that
I would like to open to the forum to discuss...
Ok

What are the pros and cons when using JavaScript as a substitute for
<include> for information contained on every page?

Pro: You can make the page do interesting things.
Con: Not everyone will be able to enjoy it.
Reality: Most people can see it just fine, but you will want to use
caution when using any client scripting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top