It is possible to serve an HTML page with an empty <body></body>
tag, where all the elements are created in JavaScript. For example, some rich UI JavaScript frameworks, such as Sencha (previously called ExtJS), rely on this technique.
However, in general you wouldn't want to use document.write()
for this. It's often better and easier to append your elements to the DOM with the appendChild()
method, or by using the innerHTML
property.
You may want to view the source of this example from Sencha, as an example. The whole UI is rendered in JavaScript:
As noted in the comments to your question, and in Tom's answer, you still need a base HTML page to serve the JavaScript code. The minimum you need is probably something like this:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>My Rich Web Application</title>
<script src="your-code.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>