Opening a New WindowHow to open a new window with JavaScriptHome/JavaScript/Basics/New Window
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:
2. 'window name'
3. 'attribute1,attribute2' Window Attributes Below is a list of the attributes you can use:
2. height=200
3. resizable=yes or no
4. scrollbars=yes or no
5. toolbar=yes or no
6. location=yes or no
7. directories=yes or no
8. status=yes or no
9. menubar=yes or no
10. copyhistory=yes or no All right, here's an example code for opening a new window:
<FORM> Test it out below:
Yes, you got a 400 by 200 window with some writing in it! Some Important Rules 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!
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.
A New Browser Window 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> Give it a try, this window has all the features!
Remember, keep everything on one line....one really, really long line! I just put the sample code on new lines so you wouldn't have to scroll forever to read everything........and your printer won't go crazy now either! Closing a New Window Hmm.....what's with the "Close Window" button you saw in the new window? How does one do do that? To use that trick, use the window.close() function in the HTML of the new window. Just put this code wherever you want the close button to show up in the new window:
<FORM> Of course, the window can be closed with the "x" symbol on the top-right of the window as well. Set the Window Position There is another set of options you can use to set the position of the new window on the viewers, but it only works with NS4+ and IE4+:
2. screenY=number in pixels
3. left=number in pixels
4. top=number in pixels Great, but how do you decide which commands to use if there are different ones for each browser? In this case, you can use both sets of commands- the browser will ignore the set it does not recognize. The example below will give you a new window 0 pixels from the left and 100 pixels from the top of your screen:
<FORM>
Now, that is a lot of work- but you can now customize a new window for your viewers! Well, that's all for now.....The next section is: Using Link Tags for JavaScripts.
Other Topics: ASP/PHP | DHTML | Java The tutorials and articles on these pages are © 1997-2010 by John Pollock and may not be reposted without written permission from the author, and may not be reprinted for profit. Disclaimer. |
|
By: John Pollock |
|