HTML
  Home arrow HTML arrow Page 5 - Uses of the New Window Command for Web Sit...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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? 
HTML

Uses of the New Window Command for Web Sites
By: Stephen Davies
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-02-26

    Table of Contents:
  • Uses of the New Window Command for Web Sites
  • Approaches to opening a link in a new window
  • BASE tag
  • Examples of common new window uses
  • Advanced Usage

  • 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
     
     
    ADVERTISEMENT


    Uses of the New Window Command for Web Sites - Advanced Usage


    (Page 5 of 5 )


    c) Advanced usage of window open

    The above examples all require an existing URL. But what if we just want to give the user a simple message? Do we need to create a new HTML file? It seems a little stupid to do such things, right? Okay, let's go ahead with a simple demonstration. When users click a link, it will open a new window with the current date/time displayed.


    <html>

    <head>

    <title>Uses of the New Window command demonstration 2</title>

    <script type="text/javascript">

    function showDateWin() {

    var date = new Date();

    var win = window.open('', '_blank', 'width=400, height=100, menubar=no, toolbar=no,
    location=no, scrollbars=no, status=no, resizable=no');

    win.document.writeln('Current Date Time: ' + date.toUTCString());

    }

    </script>

    </head>

    <body>

    <h1>window.open() demo2</h1>

    <a href="#" onclick="showDateWin();">Show Date</a>

    </body>

    </html>


    Picture 6: open a new window with dynamic content


    In the showDateWin() function, we did not specify the URL in the window.open() method, so the browser will open a blank window. Though in the second statement, "win.document.writeln('Current Date Time: ' + date.toUTCString())", we dynamically write some content in the opened window. That's like magic, isn't it?

    According to the above examples, we can see that using window.open() to open new windows is very easy and flexible. What's more, it can customize the new window feature. In this way, we can make it a specified size and hide the menu bar, toolbar, etc. to show a neat window.

    Conclusion

    With the latest XHTML specification, it is not recommended that you use the target attribute of <a> tag or <base> tag because it is not supported. The best way to open a new window is to use JavaScript, which is flexible and powerful. Keep in mind that this method requires the browser to support JavaScript; if the browser is very old or JavaScript is disabled, the links will not work. I think we don't need to worry about that though since modern browsers all support JavaScript and a lot of web 2.0 applications are based on JavaScript already, like Google's GMail.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · open new windows is in most cases - from the user's point of view - a bad idea:*...
     

    HTML ARTICLES

    - Using a 3D HTML Table as a Recordset
    - Building a 3D HTML Table
    - Maximizing and Restoring HTML Images: Layer ...
    - Completing Construction of a Database Form w...
    - Maximizing and Restoring Images in a Tabular...
    - Building the Recordset for an HTML Database ...
    - Laying Out a Database Form with HTML
    - Tabular Database Form Functions with HTML
    - Tabular Database Forms with HTML
    - Using the Find Functions for HTML Database F...
    - Sorting for Database Forms with HTML
    - Edit and Other Database Form Functions with ...
    - More Database Form Functions with HTML
    - Database Form Functions with HTML
    - Using the HTML Table Element as a Recordset






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT