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.