JavaScript
  Home arrow JavaScript arrow Page 5 - Controlling Browser Properties with Ja...
FaxWave - Free Trial.
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
eWeek
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Controlling Browser Properties with JavaScript
By: Nariman K, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 103
    2004-02-02

    Table of Contents:
  • Controlling Browser Properties with JavaScript
  • Starting at the Top
  • Moving Windows
  • Bar Tales
  • Navigating the Family Tree
  • Location is Everything
  • History Lesson
  • Down to the Document

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Help Simplify Virtualization by IBM

    Controlling Browser Properties with JavaScript - Navigating the Family Tree
    (Page 5 of 8 )

    It's interesting to note, also, that the manner in which you refer to windows changes depending on where you are when you do the referring. In order to close the current window, for example, you can always use the following:


    <script language="JavaScript">
    // close this window
    window.close();
    </script>

    However, you can also affect other windows, simply by replacing the generic name "window" with the actual name of the window. For example, let's suppose you want to close a child window (previously assigned the name "baby") from a parent window.


    <script language="JavaScript">
    // close the child window named 'baby'
    baby.close();
    </script>

    Thus, JavaScript always understands the generic object name "window" to refer to the current window. To refer to any other window, you should use the corresponding window name.

    Let's look at a simple example to see how this works. Here, the primary window consists of a menu containing links, each of which open up in a child window named "display". The child window can be closed either from the parent window, by clicking on the "Close Display Window" link, or from the child window itself, by clicking the "Close Me" link. Here's the code for the menu:


    <html>
    <head>
    </head>
     
    <
    body>
     
    <
    ul>
    <li><a href="javascript:var display=window.open
    ('http://www.melonfire.com/community/columns/trog/',
    'display');"
    >Melonfire</a>
     
    <
    li><a href="javascript:var display 
    = window.open
    ('http://www.xmlphp.com/', 'display');"
    >
    XML 
    and PHP</a>
     
    <
    li><a href="javascript:var display 
    = window.open
    ('http://www.mysql-tcr.com/', 'display');"
    >
    MySQL
    The Complete Reference</a>
    </ul>
    <a href="javascript:display.close();"><b>Close Display Window</b></a>
     
    </
    body>
    </html>

    Notice that I have prefixed the call to close() with the child window name.

    Within the pages loaded, there exists a "Close Me" link as well, which can be used to close the child window directly. Here's what one of the pages loaded into the child window might look like:


    <html>
    <head>
    </head>
    <
    body>
    <!-- 
    page content for link here -->
    <!-- 
    close window link -->
    <a href="javascript:window.close();">Close Me!</a>
    </
    body>
    </html>

    In this case, since I'm closing the current window, I can use window.close() directly without worrying about the window name.

    Thus far, I've shown you how to control the child window from the parent. It's also possible to work the other way around, controlling the parent window from the child. Every Window object exposes an "opener" property, which contains a reference to the window that created it. Therefore, even if you don't know the name of the parent window, it's still possible to access and manipulate it via this "opener" property.

    Let's take a look at a simple example, resizing the parent window from the child:


    <html>
    <head>
    </
    head>
    <
    body>
    <!-- 
    page content for link here -->
    <!-- 
    resize parent window -->
    <a href="javascript:opener.resizeTo(400,400);">Resize My Parent</a>
    </
    body>
    </html>

    More JavaScript Articles
    More By Nariman K, (c) Melonfire


     

       

    JAVASCRIPT ARTICLES

    - Getting Attention with Interactive Effects
    - Interacting with Tooltips and Previews
    - Just-in-Time Information and Ajax
    - Interactive Effects
    - Using Cookies With JavaScript
    - Understanding the JavaScript RegExp Object
    - Controlling Browser Properties with JavaScri...
    - Using Timers in JavaScript
    - Form Validation with JavaScript
    - JavaScript Exception Handling
    - Stringing Things Along
    - Understanding The JavaScript Event Model (pa...
    - Understanding The JavaScript Event Model (pa...
    - An Object Lesson In JavaScript

    Iron Speed



    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway