JavaScript Tutorial Part 6 : JavaScript Methods and Events

Let’s have a look at those document Methods. They were: open( ), close( ), write( ), writeln( ).

We’ve already done write( ), and writeln( ) is the same as write( ) except that you get a line break. So we’ll look (briefly) at open( ) and close( )

open( )

We’re not going to be using this method, but for reference purposes here’s what it does.

The default for document.write( ) is to write stuff in the current document window – the browser window. It doesn’t need to open a new window, because it already has one to work with. You can use ) to create a new document and send it things like HTML code. You could send the HTML code with document.write( ) )


close( )

This method is used to close the document you created with the open( ) method.


Two useful document Events you can use are these:

onLoad =

onUnload =

These are typically used in the BODY section of the HTML code. Here’s two pieces of code that will annoy visitors to your site:
<BODY onLoad = “alert(‘Welcome to my web page’)”>

Or when they leave your site, there’s this:

<BODY onUnoad = “alert(‘Goodbye – Have a nice day’)”>

We’ll see another way to annoy your visitors when we create a pop-up window. We’ll do that real soon. The next part will look at another object that is widely used – the navigator object.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s