The Wayback Machine - https://web.archive.org/web/20081201133219/http://www.webreference.com/html/tutorial16/6.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 16 / 6

index12345678

Tutorial 16: Client-Side Scripting 101

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Providing alternate content

One of the major problems with scripts is that they usually append to the document they are attached to. As we have said before, this information can be useful but not essential. The question that arises, however, is how to provide alternate information for browsers that do not execute scripts.

One way would be to hide HTML fragments inside scripts, but that would present problems with a browser that does understand scripts but not a particular script, or a browser whose user has turned scripting off. Such a browser would not process the contents of the SCRIPT element at all. The answer lies in the NOSCRIPT element.

The NOSCRIPT element

Context:
The NOSCRIPT element is a block element.
Contents:
The contents of the NOSCRIPT element are processed only if a script was not executed earlier in the document.
Tags:
Both the start- and end-tags are required.

The NOSCRIPT element has a double function. First of all, user agents that do not understand SCRIPT will probably also not understand NOSCRIPT, and will thus render its contents. Secondly, if a user agent does understand scripts but does not execute a particular script for some reason, it should render the contents of the NOSCRIPT element.

This is the general wording in the HTML 4.0 specification, and is more than a bit vague and unpredictable. Besides, if you use the method recommended above to check capabilities of a browser in a script, the script will technically have executed. So what do you do?

It all depends on what your script does. Most of the time, just omitting a script will have no adverse effects on your document. In cases where it does, my favourite technique is to actually include the non-scripted information in your document and use the script to hide it. For instance, imagine you have a script that prints "Good morning!", "Good afternoon!" or "Good evening!" depending on the time of day. What about browsers that don't run the script?

The first scenario is not to care, because you feel that this greeting is just an interesting gimmick and adds little information to your page (gets my vote, this one). But what if you always want a greeting, and would like to use something generic, like "Hello!" for people without scripting?

One way to do this would be to put "Hello!" in a NOSCRIPT element. However, if some other script failed to execute earlier in the page, you'd get a double greeting; as you would for browsers that don't understand NOSCRIPT but understand SCRIPT (yes, there are some of those around, too). Not to mention the problems that arise from NOSCRIPT being a block element; what if the greeting was inside a paragraph?

What I would do, was use something like the following:

<SPAN ID="greeting">Hello!</SPAN>

Now this greeting will be displayed by all browsers; however, in your script, you can have something that applies the following CSS ruleset to the document:

SPAN#greeting { display: none; }

This gets rid of the standard greeting for script-enabled browsers, but preserves document strucure if you remove the script. This approach also has its problems (e.g. what if the browser understands scripts but not style sheets?) but is very good for most "Dynamic HTML" effects ("Dynamic HTML", or "DHTML" is actually a misnomer, and should probably be called "Dynamic Styles"; it is the sum of techniques that use scripting languages to dynamically alter the presentation of documents for interesting effects. DHTML effects usually depend on CSS). A good rule of thumb, however, is that if your script requires alternate content, it shouldn't be there in the first place.

index12345678

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Copyright 2008 Jupitermedia Corporation All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A; with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior

URL: http://www.webreference.com/html/tutorial16/6.html

Produced by Stephanos Piperoglou
Created: September 15, 1999
Revised: September 27, 1999

Morty Proxy This is a proxified and sanitized view of the page, visit original site.