Forum Moderators: open

Message Too Old, No Replies

communicating between modal windows

How to do Data Exchange Between Modal Windows

         

trisonics

3:49 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



Hi Everyone,

I am opening a modal window say MW1 from a page based on uses query and showing the data in it. Here the user has options to update some data. This data is stored in an array say MW2_ARR

In this window the user can click on a button to open another modal window say MW2 which also displays some other data set. This data is stored in an array MW2_ARR. The user can now choose the add this data set MW2_ARR with the original data set MW1_ARR.

Here I am doing "window.showModalDialog.opener.MW1_ARR" to access the parent dataset but its showing an error. That "window.showModalDialog.opener" is null or is not an object.

Can someone tell me whats wrong with my approach.

Thanks

gph

11:02 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



I've never tried this but I know you need to use dialogArguments to access the parent. You also need to send "window" when opening the dialog. "window" means the entire parent is accessible through dialogArguments.

this accesses the parent from the first window.

dialogArguments.MW1_ARR

I'm guessing from the 2nd window to the parent would be this?

da = dialogArguments

da.dialogArguments.MW1_ARR

gph

11:11 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



Actually, you don't need to send the whole window.

See arguments

[msdn.microsoft.com...]

gph

11:20 pm on Sep 8, 2003 (gmt 0)

10+ Year Member



There's a better example of opening the window on the showModelessDialog page (they open the same way)

[msdn.microsoft.com...]

trisonics

6:55 am on Sep 9, 2003 (gmt 0)

10+ Year Member



Thanks for the pointers.
it seems that objects in the parent window cannot be used if frames are used.

gph

1:48 am on Sep 10, 2003 (gmt 0)

10+ Year Member



This seems to work:

- 2nd Modal to parent window

dialogArguments.dialogArguments.MW1_ARR

- 1st Modal opened from a framed page. 1st Modal opens 2nd. 2nd Modal to parent window

dialogArguments.dialogArguments.parent.MW1_ARR

Confused? I am :)

I think you'll find it easier to keep as much js in the parent as possible. Then it'll be all in one place, one step, and reusable.

parent

var MW1_ARR = ['array stuff',1]

var MW2_ARR = ['array stuff',2]

var name1_open = false;
var name2_open = false;

// (window name, Modal or Modeless, source, width, height)
function MS_win(n, m, s, w, h) {
var w = window;
if (!w[n + '_open']) {
w[n + '_open'] = true;
w[n] = w['show' + m + 'Dialog'](s, w, 'dialogWidth:' + w + 'px; dialogHeight:' + h + 'px;')
} else {
w[n].focus()
}
}


child frames
parent.MS_win('name1', 'Modeless', 'page1.htm', 200, 200);

alert(parent.MW1_ARR[1]);

// to Modeless
alert(parent.name1.document.title);

child windows

var da = dialogArguments;

onunload = function() {
da.name1_open = false
}

da.MS_win('name2', 'Modal', 'page2.htm', 200, 200);

alert(da.MW2_ARR[1]);

// Modeless to Modeless
alert(da.name2.document.title);


The function sets a global variable for checking whether a Modeless window is open. You don't need it for Modal. It is the name of the window with "_open" added to it. For example from a child window.

alert(da.name2_open);

trisonics

4:51 am on Sep 10, 2003 (gmt 0)

10+ Year Member



Thanks it worked.