Webpages and JavaScript

Discussion in 'HTML' started by SmilingPolitely, Oct 24, 2005.

  1. 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
     
    SmilingPolitely, Oct 24, 2005
    #1
    1. Advertising

  2. SmilingPolitely

    mbstevens Guest

    SmilingPolitely wrote:

    >
    > 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.
    --
    mbstevens
    http://www.mbstevens.com/preprocessor/
     
    mbstevens, Oct 24, 2005
    #2
    1. Advertising

  3. SmilingPolitely wrote:
    > 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.
     
    David Dorward, Oct 24, 2005
    #3
  4. SmilingPolitely

    rf Guest

    SmilingPolitely wrote:

    > 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.


    --
    Cheers
    Richard.
     
    rf, Oct 24, 2005
    #4
  5. SmilingPolitely wrote:
    > 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.

    --
    -=tn=-
     
    Travis Newbury, Oct 24, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGV2aW4=?=

    ASP.NET Security and Webpages

    =?Utf-8?B?RGV2aW4=?=, Jun 10, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    415
  2. Deryck
    Replies:
    3
    Views:
    371
    Deryck
    Oct 13, 2004
  3. John Ortt
    Replies:
    0
    Views:
    120
    John Ortt
    Nov 25, 2004
  4. John Ortt
    Replies:
    3
    Views:
    126
    Michael Winter
    Nov 30, 2004
  5. Brett

    Reading Webpages using javascript

    Brett, May 29, 2005, in forum: Javascript
    Replies:
    1
    Views:
    87
    Randy Webb
    May 29, 2005
Loading...

Share This Page