Here the script is not executed on loading but is triggered by the action attribute of a <form>:
Here's the code:
<form action="javascript:" method="post" name="form1"><br />
<input type="button" name="button1" value="Click me"
onclick="document.write('Hello world'); document.close();" />
</form>
The document.close(); is needed by Netscape to flush everything it has in memory to the screen before the execution of the script stops.