Sunday, December 9, 2007

Creating windows

Creating windows

Creating windows is a great feature of JavaScript. You can build new windows. Load a HTML- document. Navigate through the Internet- all with JavaScript. I'm going to show you how we can open a window and write something to it. If you push this button you will get to see what I'm going to explain to you next. Breaking up with traditions I didn't write Hello world! to the page...

Here is the source:

As always you can see the button which calles a function. The function WinOpen() creates a new window by calling the method open. The first quotes contain the URL of the page. Here you can put the address of a HTML- document which you want to load. If you leave it blank no page is loaded and you can write to it with JavaScript! The next quotes specify the name of the window. Here you can write nearly anything- this has no effect on our examples right know. But you will get an error message if you write Display Window (with a space between the two words - Netscape tells you something different in their information- but I sat half an hour because I could not find an error!) The next quotes specify the properties of the window. This is really interesting. You can tell if you want a toolbar, scrollbars... If you write toolbar=yes then you will get a toolbar in your window. There are some different properties listed below which you can change. You can specify every possible property. You have to write them the way shown above. And with no spaces between! Here is what you can change on your page:

toolbar

location

directories

status

menubar

scrollbars

resizable

copyhistory

width=pixels

height=pixels

For 'pixels' you have to write the number of pixels. This way you can tell the browser how large your window should be. After you have opened your window and called it msg (stands in front of the open- method), you can now write to your window. Here you can write normal HTML- code! This is really a great thing. You could build a HTML- document using the form input a user gave you in the document before. You could make a page where a user has to write his name to a form and then a new HTML- document is created containing his name! Some months ago this was only possible with CGI- Scripts!

No comments: