JavaScript
  Home arrow JavaScript arrow Page 2 - Controlling Browser Properties with Ja...
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 
IBM Developerworks
 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

    Virtual Tradeshows by Ziff Davis Enterprise – A Unique Opportunity to Interact with IT Experts, Access Information, and Gain Insight on Today’s Trends in Technology Learn more

    Controlling Browser Properties with JavaScript - Starting at the Top
    (Page 2 of 8 )

    I'll begin at the beginning, with the top-level Window object. The Window object is at the top of the DOM hierarchy; all other nodes are under it, including objects representing the document's frames, forms, images, links and styles. This object comes with a bunch of useful methods, of which the two most commonly-used ones are the open() and close() methods. Here's an example of using the Window object's open() method to open a new browser window:


    <script language="JavaScript">
    // open a new window
    window.open("http://localhost", "new");
    </script>

    As you will see when you run it in a browser, this line of code opens up a new window, loading the URL "http://localhost" into it. Thus, the first argument to window.open() is always the URL to be loaded, while the second is the window name.

    You can also control the appearance of the window, by adding a third argument - a comma-separated list of window attributes. Here's an example:


    <script language="JavaScript">
    // open a new window
    window.open(<A href="http://localhost">http://localhost</A>, "new",
    "toolbar=no,status=no,menubar=no,scrollbars=no");
    </script>

    Here's a brief list of the important attributes that window.open() lets you control:

    "width" - Controls the width of the new window.

    "height" - Controls the height of the new window.

    "location" - Toggles the address or location box.

    "toolbar" - Toggles the toolbar.

    "status" - Toggles the status bar.

    "menubar" - Toggles the menu bar.

    "scrollbars" - Toggles the scrollbars.

    "directories" - Toggles the directories or links bar.

    "resizable" - Is the window resizable ?

    These attributes can be turned on or off by equating them with either a 1 or 0. Height and width values must be specified in pixels.

    Thus, if you wanted to open a window with the address bar and status bar off, but the links bar on, you would use this code:


    <script language="JavaScript">
    // open a new window
    window.open(<A href="http://localhost">http://localhost</A>, "new",
    "location=no,status=no,directories=yes");
    </script>

    If instead you wanted a window of height 640 and width 480, non-resizable and with no bars showing, you could use this code:


    <script language="JavaScript">
    // open a new window
    window.open("http://localhost", "new",
    "width=480,height=640,toolbar=no,resizable=no,
    menubar=no,location=no,status=no,directories=no");
    </script>

    Note that leaving the third argument to window.open() empty pops open a window with default settings. Note also that you should not leave spaces between the various window attributes listed in the third argument to window.open() - they can cause problems with certain browsers.

    Now, how about closing a window that you've opened? It's pretty easy – just use the window.close() method, as in the following example:


    <a href="javascript:window.close()">
    Close Window
    </a>

    Now, when the user clicks the "Close Window" link above, the window should close automatically. Note that if the window you're trying to close through JavaScript is the primary browser window, browser security settings might require you to confirm your action through a dialog box.

    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 3 hosted by Hostway