View Full Version : Copying Values from a DhtmlWindow to other dhtmlwindow...

04-21-2008, 06:14 AM
1) Script Title:

2) Script URL (on DD):

3) Describe problem:
I want to copy values from one dhtmlwindow to other...
is it possible ?

hi there again..
i am trying to copy values like this:


I am getting that newdiv have zero value or there is no object...

The same trying to get values with document.all()

:-( what i am doing wrong... :eek:

Thanx in advance...

04-21-2008, 07:10 AM
It definitely should be possible, though how do to it depends on how your windows are opened- via IFRAME, Ajax, inline DIV etc? Also, just to clarify, I gather you wish to, inside WindowB, create a link that when clicked on copies the contents of a DIV on the parent Window to WindowA right?

04-21-2008, 07:47 AM
not only at parent...

but it could be and at the parent...too...

by the way i am using iframe..

can u help me?

04-21-2008, 08:01 AM
I assume the pages contained in the IFRAME are all within the same domain as the parent window's page? JavaScript doesn't allow cross domain access.

04-21-2008, 08:04 AM
yes they are open in my localhost into the same page! :-)

04-21-2008, 10:32 AM
I assume the pages contained in the IFRAME are all within the same domain as the parent window's page? JavaScript doesn't allow cross domain access.

IS AT the same domain - and same parent window's page!

04-21-2008, 02:35 PM
gouxou gouxou - i am sorry.. can anyone help at that ?

04-22-2008, 07:17 AM
Speaking in general, you can access the page contents embedded via IFRAME and shown inside the DHTML Window in the following way. Say you have the following to open a DHTML window:

var mywinz=dhtmlwindow.open("pagebox", "iframe", "test.htm", "My Web Page", "width=590px,height=350px,resize=1,scrolling=1,center=1", "recal")

And inside test.htm, you have the below form:

<input type="text" id="myname" value="George" />

Now, on your parent page, you can alert the value of the form contained inside test.htm with the code:

<a href="#" onClick="alert(window.frames['_iframe-pagebox'].document.getElementById('myname').value); return false">Get value</a>

The key is the code:


Which is how you access from the parent page the document contained inside the DHTML Window via IFRAME. Change pagebox to match the ID of the DHTML window div when you called dhtmlwindow.open() earlier.

With this info you should also be able to access the contents of one DHTML window from another. From within WindowB, just remember to first navigate back to the parent window before constructing the rest of your code to access WinA, something like:


04-23-2008, 08:13 AM
You are my man! :-)

Yo!~ !! !!! !! :-) THANK u very Much!

in Greek: se efharisto poli !

working very good !

04-23-2008, 08:20 AM
and because we are in the same subject...

how i will print from other window (iframe) one other...

for example :

i am in windowb and and i want to print windowa contents...

like this:


... ?

thanx again...

04-23-2008, 07:53 PM
Hmm try something like:


04-24-2008, 05:44 AM
thanx for answering ... but..

Hmm try something like:



not working... the message i am getting in greek is: That cannot implemented

so.. ?

04-24-2008, 09:16 PM
Hmm I just tried it in FF, and it works for me. That is to say, when executing the code I posted, I get the Print Dialog in FF...

04-25-2008, 08:16 AM
my mistake worked... fine!

04-25-2008, 08:29 AM
my mistake worked... fine!

no... not working... !! sorry


I want to print windowa and that prints WINDOWB !!!

i can't believe it.,.. in the beggining i believed that made it but i ve understand it when i put controls (buttons) at windowb (print them too)~!

why ??

04-29-2008, 11:37 AM

04-30-2008, 07:41 AM
I want to print windowa and that prints WINDOWB !!!

I'm not sure I understand. Do you mean you want to add a link inside windowA that when clicked on, prints the contents of windowB? If so, you'll also need to take into account whether windowB is still open at the time the link in windowA is clicked on.

04-30-2008, 09:25 AM
If so, you'll also need to take into account whether windowB is still open at the time the link in windowA is clicked on.

what do you mean about taking into account (windowb is open but minimized always) ?

acctually i mean this i have a button with onclick in windowa and i want to print windowb....

05-01-2008, 02:21 AM
Well, a button in windowa that prints the contents of windowb (both assumed to be IFRAME based) would just look like:


The issue I was talking about is how if the user has closed windowb already while clicking on the above link, a blank page will be printed instead. That's because when the user closes a IFRAME based DHTML window, the script empties the page out of the IFRAME first.

05-02-2008, 07:51 AM

i m gonna be crazy!

not working! - it prints itself window...

have a big table or records (Database)
have buttons Close/Add/Print
Print buttons have onclick java function printdiv(id):

function printDiv(id) {

why printing windowa ! ????

05-02-2008, 09:01 AM
You really cannot do that because browsers vary as to how they will respond. FF gets it 'right', but IE prints the iframe that has the print command on it, while Opera prints the top page:

<iframe name="wina" src="page1.htm" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
<iframe name="winb" src="page2.htm" width="300" height="300" scrolling="auto" frameborder="1"></iframe>


<div>Hi from Page1<br>
<input type="button" onclick="top.frames['winb'].print();">


Hi from Page2

If you were to print the top page, but had a print stylesheet that rendered all but the iframe containing the page that you want to print display:none, it might work out. I'm going to experiment with that and a few other things, if I have any luck, I'll let you know.

05-02-2008, 09:28 AM
OK, some progress, if I use:


Then IE, FF, and Safari 3 Win get it 'right'.

But, you cannot focus on a window that is display:none or visibility:hidden. So, you probably won't be able to print a minimized DHTML Window iframe in IE. You could if your print command brought it back from minimization, focused on it, and then printed.

Opera still got it wrong, and even when printing the top page with a print stylesheet, Opera will not do it. So, unless a way can be found to work it out for Opera, your print code could be:

alert('frame cannot be printed in Opera');
code to bring back winb from minimization

05-05-2008, 08:10 AM
thank you all...

i ve found the solution

jscheuer1: top.frames['winb'].xxxxxxxxx not working - must use top.frames['_frame-winb'].xxxxxxxxx to work...

but the way you thought is right the ie must find windows opened not with focus but restored!

now working sweet!

Thank you all !

05-05-2008, 12:43 PM
The 'winb' named iframe was in my demo, of course it would need to be changed to the name of your iframe. And, if you are lucky, you would be able to do more than just bring the DHTML window back from minimization, for IE. You could perhaps detect if it were minimized or not, and if so bring it back to print it and then minimize it again. Perhaps this could be done so quickly that the user wouldn't even notice, or wouldn't notice much.