spacer

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

home / programming / javascript / domloader current pageTo page 2
[next]

Value Added Scripts

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

DOM-Based Conditional Script Loading in JavaScript

By Kenneth Tibbetts (postmaster@yankeeweb.com)

It can be tough to be practical and ethical at the same time. Ethically, I believe in the W3C recommendations. I believe in advancing and supporting accessibility and the document object model (DOM). The Internet should exclude the fewest possible people. But practically speaking, I write code. And the code that I write usually requires a modern, document object supportive browser to really do its stuff.

My pages begin life as ordinary HTML and CSS. When I add scripts to these clean, valid pages, I wind up with something everyone can use, to some extent. If I am very, very careful.

It is not too difficult to write pages that work in either and both of these cases:

  1. Browsers (and other software) without script support, or scripting turned off.
  2. Browsers that support the latest version of the JavaScript language.

It is fairly easy to write scripts that work in the newest browsers. The trouble starts when the real world gets online, with browsers that support some but not all of the script. Give a half-smart browser enough code and it'll hang itself.

I run a small shop, with a small budget. I don't have a test machine for every platform. I want to deliver my scripts only to the visitors that can use them.

Dead Language

If you set up your pages to run basic HTML, and limit the built in events to hyperlink navigation and server based forms, any page can display in any browser. Any other events can be built in scripts, and you can restrict the visitors who load the scripts to the folks who can use them. To each according to his ability.

In HTML, before the W3 put the kibosh on the language attribute, you could screen the browsers by setting a version number of the language in the script tag:

<script language="JavaScript1.5" src="srcfile.js"></script>

This would prevent a browser that didn't support version1.5 from loading the file.

You could get fancier, and load different scripts for various levels of support:

<script language="JavaScript"    src="srcfile1.js"></script>
<script language="JavaScript1.2" src="srcfile2.js"></script>
<script language="JavaScript1.5" src="srcfile3.js"></script>

Scripts here are cumulative. The first script loads in any browser that supports the src attribute for external scripts. If number 3 loads, you can count on having the first two as well. Each can have an onload handler--the last handler assigned will be used when everything finally loads.

I wrote a lot of code like this, back when. But no more.


home / programming / javascript / domloader current pageTo page 2
[next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
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
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
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
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
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
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

Created: April 30, 2002
Revised: April 30, 2002

URL: http://webreference.com/programming/javascript/domloader/