Web-centric Computing

Some Example Code

JavaScript Dual Presentation

Part 2: How it is done

The essential parts of the markup are:

   <body>
   <!-- ... -->
   <script 
     type="text/javascript"
     src="dual_presentation.js">
   </script>
   <noscript>
     This is the text that users
     <em>without</em> Javascript
     will see.
   </noscript>
   <!-- ... -->
   </body>
  

If the browser supports JS

If JS is understood by the browser then the <script type="text/javascript" ...></script> is run.

The file it loads contains document.writeln statements. Those statements create virtual markup that the browser writes into a buffer and then reads as though they had appeared in place of the <script> ... </script>.

[view the Javascript file]

Otherwise

But if JS is not understood by the browser then the browser presents the markup in the noscript container instead.


Questions

  1. Why will this technique work even with browsers that were written before Javascript was invented (for example, Netscape version 1)?
    1. What is the name we use for that concept?
    2. What is another example of that concept in HTML?
  2. Why is the type="text/javascript" in the script necessary?
  3. Why do you think the script element has an open and close tag (but never any contents)?

But what about the pop-up dialogue box?

Where did that annoying dialogue box come from?



http://www.cs.dal.ca/~jamie/course/CS/4173/examples/JS/dual_presentation/how.html
Version:
25 April 2002
Author:
J. Blustein <jamie@cs.dal.ca>