spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / diaries / 8

[previous] [next]

Senior Consultant/Information Security - permanent position (TX)
Next Step Systems
US-TX-Irving

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

The JavaScript Diaries: Part 8

By 

moveBy()

This method is used to move a window to a new location on the screen. The window is "moved by" the number of pixels given within the parameters in the method. You might use it to move a window out of the way of something on the parent window. (The "parent" window is the original window that opened the new window, which would be considered the "child".) The format for this method is:

window.moveBy(xDistance,yDistance);

The first parameter (shown as "xDistance" above) is the number of pixels the window will be moved from side to side. A positive number will move the window to the right, a negative number will move the window to the left. The other parameter (shown as "yDistance") will move the window up and down. A positive number will move the window down, a negative number will move it up. The window will move from its current position, according to the number of pixels, each time the method is invoked. If you kept pressing the "Move Window" button in the example below, the window would move 50 pixels across the page and 50 pixels down the page from its present position when the button is pressed. (You can see how it works by pressing the link here > JavaScript Demo.)

<form>
  <input type="Button" value="Move Window" onclick="window.moveBy(50,50);">
  <input type="Button" value="Close Window" onclick="window.close();">
</form>

Note: This method is best used in opening new windows. In Netscape (7.2), using the moveBy method in the main browser window will cause the browser to resize and move down the screen. In IE (6.0), the window moves down the screen, as in Netscape, but it doesn't resize. Also, in IE it's not possible to move the window by dragging it. In Firefox (1.06), the browser just resizes.

moveTo()

This method is used to "move the window to" a specific location within the screen. It's useful in placing a new window at a specific location on the screen. The format is:

window.moveTo(xDistance,yDistance);
The first parameter (shown as xDistance above) is the number of pixels the window is to be located from the left side of the screen. The second parameter (shown as yDistance) is the number of pixels the window is to be located from the top of the screen. This method does not take negative numbers nor does it continue to move if the method is reinvoked, as does the moveBy() method. (You can see how it works by pressing the link here > JavaScript Demo.)
<form>
  <input type="Button" value="Move Window" onclick="window.moveTo(50,50);"><br>
  <input type="Button" value="Close Window" onclick="window.close();">
</form>

Note: As with the moveBy method, the best use of this method is in the opening of new windows. In Netscape (7.2), using the moveTo method in the main browser window will only cause the browser to resize. In Firefox (1.06), the browser will resize, and then, when pressed a second time, relocate on the screen. In IE (6.0), the window is resized. Also, in IE, it's not possible to move the window by dragging it.

print()

This method is used to print the contents of the current window. When it's called, it opens the browser's print dialog box. The format is:

window.print();
An example would be:
<form>
  <input type="Button" value="Print page" onclick="window.print();">
</form>

resizeBy()

This method is used to resize an existing window. It will increase or decrease the size of the window according to the stated parameters. For example, if the current window is 300 pixels wide by 400 pixels high, and the method given is resizeBy(150,50), the window will be resized to 450 pixels wide by 450 pixels high (300+150=450 wide and 400+50=450 high). The top left portion of the window will remain where it is. The rest of the window will expand out from that position. If the method is used again with the same stated parameters, resizeBy(150,50), the window would resize to 600 pixels wide by 500 pixels high (450+150=600 wide and 450+50=500 high). The format is:

window.resizeBy(xSize,ySize);

The first parameter (shown as xSize above) determines the distance, in pixels, of the window from the left side of the new window, increasing or decreasing the current size of the window. The second parameter (shown as ySize above) determines the distance, in pixels, of the window from the top of the browser window, increasing or decreasing the current size of the window. Positive numbers make the window larger, negative numbers make it smaller. The method only affects the lower right-hand corner of the window as it resizes from the top, left hand corner. The top, left hand corner does not move. The window is sized from there. If you only need to adjust one parameter, set the other one to "0" (zero) as both are required.

<form>
  <input type="Button" value="Move Window" onclick="window.resizeBy(150,50);"><br>
  <input type="Button" value="Close Window" onclick="window.close();">
</form>

In this example the browser window will be increased by 150 pixels in width and 50 pixels in length, starting at the top, left hand corner.

resizeTo()

This method is used to resize an existing window. Unlike resizeBy(), which increases or decreases the size of the window by a given parameter, resizeTo() will change the entire size of the window according to the stated parameters. i.e. It will "resize the window to." The measurements, in pixels, are the actual width and height of the outer dimensions of the window. For example, if the current window is 300 pixels wide by 400 pixels high and the method given is resizeTo(250,500), the window will be resized to 250 pixels wide by 500 pixels high. The orignial size does not matter. The format is:

window.resizeTo(xWidth,yLength);

Together, the two parameters determine the new size of the window:

<form>
  <input type="Button" value="Move Window" onclick="window.resizeBy(350,250);"><br>
  <input type="Button" value="Close Window" onclick="window.close();">
</form>

In the example above the window will be resized to 350 pixels wide and 250 pixels long.

home / programming / javascript / diaries / 8

[previous] [next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle

Created: August 19, 2005

URL: