Javascript: a little window


Now let's see a nice script. I'm going to show you the window object. You can define a window, and you can put you HTML page inside of it! I think this object is helpful to build a little guide to help your page's visitor. For example, click on the help word...

This is a little help...

And this is the HTML page:

<html><title> JavaScript window</title>
<HEAD><SCRIPT language="JavaScript">
<!-- Begin
function display_image() {
mywindow=window.open( color="#FF0000">"","help","toolbar=0,location=0,
directories=0,status=0,menubar=0,
scrollbars=1,resizable=0,copyhistory=0,width=285,
height=255,screenX=500,screenY=100" color="#00FF00">);>
mywindow.document.write("<HTML><HEAD>");
mywindow.document.write("<TITLE>Help</TITLE>");
mywindow.document.write("</HEAD><BODY BGCOLOR=000000 TEXT=54FF9F><HR>");
mywindow.document.write("This is a window object. You <br>");
mywindow.document.write("have to use the open method <br>");
mywindow.document.write("to build this object. So you <br>");
mywindow.document.write("have to write a line of code <br>");
mywindow.document.write("like this: 'window.open()'. <br>");
mywindow.document.write("In addition you can write <br>");
mywindow.document.write("inside the defined window. <br>");
mywindow.document.write("You can also write an HTML <br>");
mywindow.document.write("page, by means of the HTML <br>");
mywindow.document.write("tags. In order to write your <br>");
mywindow.document.write("page, you have to use the <br>");
mywindow.document.write("write method. The code is: <br>");
mywindow.document.write("window.document.write(\"any <br>");
mywindow.document.write("thing you want to write\"); <br>");
mywindow.document.write("For example, you can write <br>");
mywindow.document.write("something like this: <br>");
mywindow.document.write("&lt;html&gt&lt;head&gt&lt;/head&gt&lt;body&gt<br>");
mywindow.document.write("This is an HTML page<br>&lt/body&gt ");
mywindow.document.write("&lt/html&gt <br>");
mywindow.document.write("You can close your window <br>");
mywindow.document.write("by using the close method. <br>");
mywindow.document.write("Therefore you have to write <br>");
mywindow.document.write("something like this: <br>");
mywindow.document.write("'window.document.close()'; <br>");
mywindow.document.write("Finally, you can define the <br>");
mywindow.document.write("window's properties by means ");
mywindow.document.write("of the open method.");
mywindow.document.write("<HR><center><FORM><INPUT TYPE='button' VALUE='Close' onClick='
window.close()'></FORM>");
mywindow.document.write("</CENTER>");
mywindow.document.write("</BODY></HTML>");
}
// End -->
</SCRIPT>
</head>

<body>
<CENTER>This is a little <a href="javascript:display_image()">help</a>...
</CENTER>


</body>

</html>

In order to build the window object, you have to define it, by means of the window.open method:

mywindow=window.open( color="#FF0000">"","help","toolbar=0,location=0,
directories=0,status=0,menubar=0,
scrollbars=1,resizable=0,copyhistory=0,width=285,
height=255,screenX=500,screenY=100" color="#00FF00">);

mywindow is the window's name. You have to name your window if you want to set its properties. In other words it means: 'build a window object named mywindow'.

Window.open("url","name","window_features") is the method to build your window. Where url is optional (here you can load an HTML page pointed by the url), name is the window's name (you can use it to refer the window) and window_features are the default window's properties. You can write inside of the window by means of the write method:

mywindow.document.write("anything you want to write here...")

Where mywindow is the window's name, document is a property of mywindow (but it is an object too...remember the object hierarchy), and write() is the method. You can also close the window by means of the window.close() method. By means of the window_features parameter, you can set a toolbar, the url location field, the status bar, the scroll bar and so on. Look at Objects, properties and methods to find out the properties.


Index           Home  Back       About  Contact us!

Copyright (c) 1998-2006 Wowarea