New Script Resulted from Two Original Scripts

This section provides a tutorial example showing how the Web browser fails to execute the JavaScript code resulted from two original JavaScript codes.

Actually, the Web browser processes new script code correctly only if it is resulted from a single execution.

Here is HTML document with two JavaScript codes that works together to return a new JavaScript code:

<!-- Hello_Nested_Script_Error.html
   Copyright (c) 2002, All Rights Reserved.
<head><title>Hello from Nested Script Error</title></head>
<script type="text/javascript">
   document.writeln("-- Before the new script.");
   document.writeln("<script type=\"text/javascript\">");
document.writeln(\"Hello World!\");
<script type="text/javascript">
   document.writeln("-- After the new script.");

After the first round of JavaScript execution, the HTML document would have a new JavaScript code like this:

-- Before the new script.
<script type="text/javascript">
document.writeln(\"Hello World!\");
-- After the new script.

If the Web browser executes the new JavaScript code again correctly, the final HTML document would look like this:

-- Before the new script.
Hello World!
-- After the new script.

But both Internet Explorer and Firefox give the following result:

-- Before the new script.

Conclusion: if a new script code is returned from two original script codes, the Web browser will fail to execute it correctly.

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

Server-Side and Client-Side Web Scripting

 Web Scripting Architecture Overview

 Server-Side Scripting Overview

 Client-Side Scripts for Document Updating

 Client-Side Scripts for Event Handling

 Client-Side Scripting Processed Multiple Times

New Script Resulted from Two Original Scripts

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications


 Full Version in PDF/EPUB