tags:

views:

120

answers:

3

I have parent browser window P . on clicking a button a new browser window WIN-A is opened. then again pressing the same button it should read the title of the WIN-A window and open WIN-B

how to achieve this using Javascript?

Thanks in advance

+1  A: 

A similar question was just asked recently:

Stack Overflow question: Quickest way to pass data to a popup window I created using window.open()?

Using that as a base (and provided Parent and WIN-A are on the same domain):

// Put outside click handler
var winA = null;

// Put inside click handler

if(!winA){
    // Store the return of the `open` command in a variable
    var winA = window.open('http://www.mydomain.com/page1');
} else {
    var title = winA.document.title;
    // Do something with title
    var winB = window.open('http://www.mydomain.com/page2');
}
Doug Neiner
A: 

Given:

var myWindow = open("foo.bar");

Old method: Change the window object's name property:

myWindow.name = "...";
// in foo.bar:
setInterval(someFunctionToCheckForChangesInName, 100);

HTML5 method: Call the window object's postMessage method:

myWindow.postMessage("...", "*");
// in foo.bar:
(window.addEventListener || window.attachEvent)(
  (window.attachEvent && "on" || "") + "message", function (evt) {
    var data = evt.data; // this is the data sent to the window
    // do stuff with data
  },
false);
Eli Grey
I had never seen the (possibly_present_func_one || possibly_present_func_two )( args, args ); technique before. Cool.
Trevor Harrison
Trevor: Don't forget to use `.call(the_object_that_is_supposed_to_be_the_parent, args)` if it's not a property of `window`.
Eli Grey
A: 

When you call window.open, it returns a reference to the newly opened window. You can store the references to the windows you open in an array, and then iterate that array when you need to open another new window.

Gabriel

Gabriel McAdams