web-developer
HomeWindows/IISDHTMLRankingIndex ServerContact me 
 


 

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:

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

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

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

Window Attributes

Below is a list of the attributes you can use:

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

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

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

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

  5. 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.).

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

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

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

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

  10. 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('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200')">
</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!

  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.

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>
<INPUT type="button" value="New Window!" onClick="window.open('http://www.pageresource.com/jscript/jex5.htm','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!

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>
<INPUT type="button" value="Close Window" onClick="window.close()">
</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+:

  1. screenX=number in pixels
    Sets the position of the window in pixels from the left of the screen in Netscape 4+.

  2. screenY=number in pixels
    Sets the position of the window in pixels from the top of the screen in Netscape 4+.

  3. left=number in pixels
    Sets the position of the window in pixels from the left of the screen in IE 4+.

  4. top=number in pixels
    Sets the position of the window in pixels from the top of the screen in IE 4+.

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>
<INPUT type="button" value="New Window!" onClick="window.open('jex5.htm','mywindow','width=400,height=200,left=0,top=100,screenX=0,screenY=100')">
</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.....



Web Developer - Larry Boeldt - Home Page
Solid-State Disks Can Increase SAN and Application Performance
Yahoo Messenger Protocol
Backup And Restore of the IIS Metabase
Cool DHTML Menubar
Cool DHTML Pop IT Link Menu
Cool DHTML Contractable Headers
Cool DHTML Hover Popup Bar
Cool DHTML Slide In Menu
Cool DHTML - Slide in external menu
Cool DHTML Highlight menu Effect IE
Cool DHTML CSS Highlight menu
Cool DHTML Right Click menu
Cool DHTML Smart Folding menu
Cool DHTML Flash Form Elements
Cool DHTML Dissolving Text
Cool DHTML Window
Cool DHTML rain-snow affect
Cool DHTML Falling Leaves
Cool DHTML Bubbles
Cool DHTML PopUp
cgi
DHTML A Slackers Guide
tomcat iis
Cool DHTML Fade in slide show
Cool JavaScript Tripple Combo Dropdown
Cool_DHTML_Home
page_index
HTML Symbol Codes, HTML Character Codes
IIS_creating_and_configuring_web_app
IIS - set the application protection for a web site using script
Cool_DHTML_Bats
Cool_DHTML_Effects_Slide_In
Cool_DHTML_Drag_and_Drop_1
Cool_DHTML_Generic_Drag_and_Drop
Cool_DHTML_ToolTips_1
Cool_DHTML_Resizeable_area
Cool_DHTML_Favorite_Bar
image_composer_rounding_corners
IIS Appendix I from Wrox ASP 2.0 - A great reference to IIS.
ODBC
Ranking
IP_Protocol_Numbers
Larry Boeldt - WI, Sheboygan, Web Developer, Technology Architect
ISS_Index_Server_ADO
ranking_be_search_engine_friendly
ranking_10_steps_to_building_traffic
ranking_raise_to_the_top
ranking_drive_company_sales
iss_home
ISS_Index_Server_XML_Filter
Javascript_Window.Open
Developer_Books_Graphics
SQL Function to autofill Sort Fields
Windows XP Tips and Tricks 2003-08-08
scripting_set_default_language
xp_hangs_on_rightclick
Cascading Style Sheets - Useful Sites and pages
Change MSDE Port Number