JavaScript Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.11

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 by Dr. Herong Yang, http://www.herongyang.com/
-->
<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.

Sections in This Chapter

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

Dr. Herong Yang, updated in 2008
New Script Resulted from Two Original Scripts