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:

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

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!\");
</script>
-- 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

 AJAX (Asynchronous JavaScript And XML)

 References

 Full Version in PDF/EPUB