JavaScript
  Home arrow JavaScript arrow Page 3 - Working with Pop Ups and Browser Windows i...
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 
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? 
JAVASCRIPT

Working with Pop Ups and Browser Windows in JavaScript
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2006-04-25

    Table of Contents:
  • Working with Pop Ups and Browser Windows in JavaScript
  • How to write to a pop up window dynamically using JavaScript
  • How to access the data available in a pop up window from within the main window using JavaScript
  • How to access the data available in the main window from within a pop up window and vice versa using JavaScript
  • How to access the data available in main window from within a popup window and vice-versa using JavaScript: discussion

  • 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


    Working with Pop Ups and Browser Windows in JavaScript - How to access the data available in a pop up window from within the main window using JavaScript


    (Page 3 of 5 )

    Now, let us try to develop a simple script (JavaScript) which writes user specified information to a pop up window dynamically.  We shall even access the information available in pop up window from within the main window!  Have a look at the following code:

    <html>
          <head>
                <meta  name=vs_targetSchema
     content="http://schemas.microsoft.com/intellisense/ie5">
    <script  id="clientEventHandlersJS"  language="javascript">
    <!--
    // global variable for subwindow reference
    var w;
    function openNewWindow( ) {
          if (!w || w.closed) {
            w = window.open("","NewWindow","status,height=200,width=300");
            // delay writing until window exists in IE/Windows
            setTimeout("openNewWindow( )", 50);
        } else if (w.focus) {
            // window is already open and focusable, so bring it to the front
            w.focus( );
        }
        // assemble content for new window
        var c = document.all.txtHTML.value;
        // write HTML to new window document
        w.document.write(c);
        w.document.close( ); // close layout stream
    }

    function Button1_onclick() {
          openNewWindow();
    }

    function Button2_onclick() {
          alert(w.document.getElementById("txtName").value );
    }

    //-->
                </script>
          </head>
          <body>
                <form  id="form1">
                      Enter HTML:<textarea  id="txtHTML"
     NAME="txtHTML"><html><head><title>My sub  Window</title></head><body>Enter Name: <form id="Form1"><input
    id="txtName" type=text></form></body></html></textarea><br>
                      <input  type="button"  value="Show"  id="Button1"
     
    name="Button1"  onclick="return Button1_onclick()">
                      <input  type="button"  value="Get"  id="Button2"
     name="Button2"  onclick="return Button2_onclick()">
                </form>
          </body>
    </html>

    This is another interesting concept pertaining to the use of pop up windows.  We will certainly know about retrieving information available on the current web page.  But, how about accessing the information available in a pop up window from within the main window?  This section does the same.

    The following is the function I used to achieve this:

    functionButton2_onclick() {
          alert(w.document.getElementById("txtName").value );
    }

    I am expecting that the pop up window contains a text box named "txtName" and I am trying to access the information available in it.  To access the information in a pop up window from within the main window, we need to work with the "document" object of the pop up window.  Once you get the "document" object, the rest of the routines will be very similar to the ordinary way we implement in main windows.

    More JavaScript Articles
    More By Jagadish Chaterjee


       · The example scripts are only supported by Internet Explorer since he uses...
       · Hai, get in touch with popups and browser windows using basic JavaScripts.
       · Yes this work only with IE. But give information a lot.Just wonder is opener is...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT