Improve Site Performance Increase Site Traffic Monitor Site Uptime Webmaster Resources NetMechanic Home Looking For Help? Partner Programs Privacy Policy Contact Us Press Room
NetMechanic Home LOGIN | HELP | ABOUT US | PRODUCTS | SITE MAP
NetMechanic Menu
Over 52 Million Web Pages Tested!     
 
search engine submission service.
Search for:


Your Email:

I would like to receive my newsletter in:
HTML format
Text format


search engine listing.
Volume 8 (2005)
   September
   June
   April
   March
   January

Volume 7 (2004)
   November
   September
   July
   June
   May
   April
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 6 (2003)
   December
   November (Part 2)
   November
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 5 (2002)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 4 (2001)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 3 (2000)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June
   May
   April
   March
   February
   January

Volume 2 (1999)
   December
   November
   October
   September
   July
   June
   May
   April
   March
   February
   January

Volume 1 (1998)
   December
   November
   October
   September

 

JavaScript Tip:
Put Your Window Where You Want It

by Larisa Thomason,
Senior Web Analyst,
NetMechanic, Inc.

  
April 2001
Vol. 4, No. 7
 • Promotion Tip
 • Design Tip
 • JavaScript Tip
  

Our February 2000 Beginner Tip showed you a neat way to send all external links to a single browser window. But if you're comfortable with a little more complicated code, it's also easy to use a JavaScript function to control the size and placement of the new browser window.

Bypass A Netscape Bug

When you open a new browser window in Netscape, it's the same size as the current window and it displays directly on top of the current window! So when visitors using Netscape click on an external link, your Web site is completely obscured.

Veteran users are used to this effect, but it can confuse beginners. Although approximately 3/4 of your visitors are probably using some version of Internet Explorer, you don't want to ignore the rest.

Besides, sometimes you want to open a new window to display a page within your own site: a table of contents, a class schedule, a contact list, etc. In this case, it's even more important to control the window's size and placement.

JavaScript Syntax

Use the window.open method to open a new browser window and define its content, size, and location. The syntax goes like this:

window.open(URL,TARGET,FEATURES)
  • URL is the URL address that the link refers to.
  • Target tells the browser where to open the window (this is important if your page uses frames).
  • Features tells the browser where to place the new window and defines the size.

Important things to remember:

  1. The order of the attributes matters! You must define them in this exact order (URL, TARGET,FEATURES) for the script to execute properly.
  2. The list of Features should be all one string: enclose it in single quotes.
  3. Even if you don't specify a Target attribute to give the new window a name, you must include a placeholder - an empty string.

Write Your Function

Although you can simply include the JavaScript code inside the link, it's better to write it as a function. Then, you can call the function as many times as you want on your Web page and still have the links open in the same browser window.

This technique gives you the same benefit as using the TARGET attribute alone inside an tag, but you have much more control.

Define the function inside your page's HEAD tag like this:

A little explanation:

  1. The function's name is newWindow and its parameter is named newContent.
  2. winContent is a variable where we open the Window object and set the parameters. The value of this variable will be stored in newContent.
  3. The name of the new window is nextWin and it will be located in the top right-hand corner of the page. The size is 350 pixels wide by 350 pixels high.
  4. Depending on the purpose of your window, you may not want to use the last 3 attributes: toolbar, scrollbars, and resizable. When you include them, your visitors will see a fully-functional browser window.

Now, you're ready to call this function inside the BODY section of your Web page like this:

Of course, you can use any URL and text you want.

Test It Here!

See how it works on our page. Click on each of the 3 links below without closing the new window. You'll see each page load inside the new window while this newsletter story remains open for your reference!

Promote your site with Search Engine Power Pack.

Quickly find display errors with Browser Photo.

Speed up your pages with GIFBot.

This technique gives you much more control over your page display and layout than merely using the TARGET attribute in your HREF tag.



Rate This Tip:
Not Useful Useful Very Useful   
 
NetMechanic Tools
HTML Toolbox
Browser Photo
Server Check
Search Engine Starter
Search Engine Tools
GIFBot
Newsletter
HTML Tutorial and Tips
Search Engine Tutorial
Accessibility Information
Browser Problem Tutorial

Company Info
Products
About Us
Contact
Advertise
Link To Us
Jobs
Privacy Policy
Partner Programs
Press Room
RSS Feed
Support
 



Powered by Overture!

 
     
 
   
 
     


Keynote Home
Copyright © 1996-2007,
Keynote NetMechanic
All rights reserved.