opening a new Browser window using Javascript
    To open a new window, you will need to use yet another ready-made 
    JavaScript function. Here is what it looks like: 

    window.open('url to open','window name','attribute1,attribute2') 

    This is the function that allows you to open a new browser window for the viewer to use. Note that all the names and attributes are separated with a comma rather than spaces. Here is what all the stuff inside is: 

    'url to open' This is the web address of the page you wish to appear in the new window. 

    'window name' You can name your window whatever you like, in case you need to make a reference to the window later. 

    'attribute1,attribute2' As with alot of other things, you have a choice of attributes you can adjust. 

    Below is a list of the attributes you can use: 

    width=300 Use this to define the width of the new window.

    height=200 Use this to define the height of the new window.

    resizable=yes or no Use this to control whether or not you want the user to be able to resize the window. 

    scrollbars=yes or no This lets you decide whether or not to have scrollbars on the window. 

    toolbar=yes or no Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.). 

    location=yes or no Whether or not you wish to show the location box with the current url (The place to type http://address). 

    directories=yes or no Whether or not the window should show the extra buttons. (what's cool, personal buttons, etc...). 

    status=yes or no Whether or not to show the window status bar at the bottom of the window. 

    menubar=yes or no Whether or not to show the menus at the top of the window (File, Edit, etc...). 

    copyhistory=yes or no Whether or not to copy the old browser window's history list to the new window. 

    All right, here's an example code for opening a new window: 

    <FORM> 
    <INPUT type="button" value="New Window!" 
    onClick="window.open('javamain.html','mywindow', 
    'width=400,height=200')"> 
    </FORM> 

    Test it out below: 

     
    Yep, you got a 400 by 200 window with some writing in it. Before we move on, we need to make note of some things so you won't go insane like I did trying to get this to work right! 

    1) When you get to the INPUT tag, keep everything in that tag on one single line in your text editor, including the javascript commands. (The text goes to the next line on this page so you can print it out easily). 

    2) Once you come to the onClick=" ", don't leave any spaces between anything. Just use the commas and the quote marks. Any white space will keep it from working correctly in Netscape. 

    3) Don't put quote marks around the yes, no, or numbers for the attributes. You only use single quotes around the entire set of attributes. 

    4) In some browsers, you may need to substitute the number 1 for yes, and the number zero for no in the attributes section. The yes or no should work fine, though. 

    Okay, enough rules. Let's look at the code that makes a completely new browser! Basically, you just use yes for all of the attributes. Here is the code: 

    <FORM> 
    <INPUT type="button" value="New Window!" 
    onClick="window.open('javamain.html','mywindow','width=400,height=200,toolbar=yes, 
    location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, 
    resizable=yes')"> 
    </FORM> 

    Give it a try, this window has all the features! 


    Note:  You have to remember to keep everything on one line....one really, really long line!
    The sample code is separate lines so you wouldn't have to scroll forever to read the lines.


    Mouse Over

    On many pages you see that people have images that change to another image when you move the mouse across the image. Well, I am going to give you a brief overview of how to go about doing this. However, I would like to say that if your audience has only 28.8 modems, it probably would be a good Idea to keep the image size down for things that you are using moveover with, since you have to load both of the images before viewing the page. If your're using big images that is. I found this code on a great page for looking at Javascripts, Cut-N-Paste Javascript.

    File Creation on the Server

    You can get infomation from a file on the server, but cannot write files to your system because of the major security risks involved with such a process. People could steal things from you, give you virii, or steal you thesis, so people being able to write to a file on your system would be very bad.


    This is all that I have for now in the tutorial about Javascript.

    Back to the main java/javascript Tutorial Main page

This page was created by Bob Perini 
For CS 763(Web Seminar) at SUNY Buffalo