help with iframes...

I split the main window into 2 frames vertically using iframe in xul...
i dont know how to write to the first frame using the document.write function. how do i get the handle to the document of the first frame..
plz explain me with little example code...

<?xml version="1.0"?>

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="example-window" title="Example 4.6.1"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<vbox flex="1">
<iframe id="content-1" width="60" height="20" src="w1.html"/>
<splitter collapse="before" resizeafter="farthest">
<grippy/>
</splitter>
<iframe id="content-2" width="60" height="20" src="w2.html"/>
</vbox>

</window>
[909 byte] By [gsatyaprakash] at [2007-11-20 11:17:00]
# 1 Re: help with iframes...
If you are trying to call between frames, you need to reference the parent first.

parent.document.getElementById('iframe_id')
PeejAvery at 2007-11-8 0:43:19 >
# 2 Re: help with iframes...
ya after i get the handle of the frame with
var hand = mywind.document.getElementById('frame_id');

how do i use hand to write to the frame using "document.write" ?
shud i say hand.write() ? that doesnt work...
shud i say hand.document.write() ? that too doesnt work...

shud i say var tmp = hand.contentDocument;
tmp.document.write() ?? this too doesnt work i guess...

plz lemme kno wat may i do to write to the frame ?
gsatyaprakash at 2007-11-8 0:44:17 >
# 3 Re: help with iframes...
hand.document.write() ? that too doesnt work...
I will work if you are truly grabbing the window. If you aren't grabbing, then of course it won't work.

ya after i get the handle of the frame with
var hand = mywind.document.getElementById('frame_id');
You are replacing "frame_id" with the actual frame id aren't you? Also, as I stated before, if you are calling an iframe from another iframe, you need to use the parent.

To test to see if you actually grabbed the window, alert its innerHTML. If the source is alerted, then you have it.
PeejAvery at 2007-11-8 0:45:17 >
# 4 Re: help with iframes...
I cant alert the innerHTML in XUL..
I am sure I am grabbing the window...
Still i get the error 'hand.document' has no properties...
gsatyaprakash at 2007-11-8 0:46:17 >
# 5 Re: help with iframes...
I cant alert the innerHTML in XUL..
I am sure I am grabbing the window...
If you aren't able to read anything from the document, then you aren't grabbing the window.

Can you post your two frame source codes please? That will help shed some light on this. Please remember to use [code] tags.

[code]
post your code here
[/code]
PeejAvery at 2007-11-8 0:47:24 >
# 6 Re: help with iframes...
frame.xul

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="example-window" title="Example 2.2.1"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >

<iframe id='m' src="chrome://window/content/mainframe.xul">
</iframe>

<splitter/>
</window>

maiframe.xul

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="example-window1" title="Example 2.2.1"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >

</window>

script code

function openPopupMenu(){

mywind=
window.open( "chrome://window/content/frame.xul", "Message", "chrome,scrollbars=1,height=300,width=800");

mywind.onload = openmenu;
}

function openmenu(){

var hand = mywind.document.getElementById('m');
alert(hand);
hand.document.write('india');

}
gsatyaprakash at 2007-11-8 0:48:18 >
# 7 Re: help with iframes...
Try the following...

function openPopupMenu(){
mywind = window.open( "chrome://window/content/frame.xul", "Message", "chrome,scrollbars=1,height=300,width=800");
mywind.onload = function(){
mywind.document.write('india'); // maybe try this instead of mywind
};
}
PeejAvery at 2007-11-8 0:49:24 >
# 8 Re: help with iframes...
that said 'mywind.document.write' is not a function...

then i tried...

function openPopupMenu(){
mywind = window.open( "chrome://window/content/frame.xul", "Message", "chrome,scrollbars=1,height=300,width=800");
mywind.document.open();
mywind.onload = function(){
mywind.document.write('india'); // maybe try this instead of mywind
};
}

this gave me no error... but i dint show me anything on the window...

i cudnt understand why the code u gave me will write to the 'iframe' instead of the document... my intention is to write to the particular iframe
gsatyaprakash at 2007-11-8 0:50:25 >
# 9 Re: help with iframes...
my intention is to write to the particular iframe
Oops. I forgot that part.

function openPopupMenu(){
mywind = window.open( "chrome://window/content/frame.xul", "Message", "chrome,scrollbars=1,height=300,width=800");
mywind.onload = function(){
var theFrame = mywind.document.getElementById('m');
theFrame.document.write('india'); // maybe try this instead of mywind
};
}
However, I find it odd that it is not recognizing the write() function. If the above code does not work with this or mywind, you should then research if write() works with Thunderbird.
PeejAvery at 2007-11-8 0:51:30 >
# 10 Re: help with iframes...
Now it says the 'theFrame.document' has no props...

I m sure write() works with thunderbird cuz i have used it...

i have also tried this...

var testFrame = mywind.document.getElementById('m');
var doc = testFrame.contentDocument;
if (doc == undefined || doc == null){
doc = testFrame.contentWindow.document;

}
doc.open();
doc.write('india');
doc.close();
gsatyaprakash at 2007-11-8 0:52:23 >
# 11 Re: help with iframes...
Try dropping the id and using a name.

function openPopupMenu(){
mywind = window.open( "chrome://window/content/frame.xul", "Message", "chrome,scrollbars=1,height=300,width=800");
mywind.onload = function(){
mywind.document.FRAMENAME.document.write('india'); // maybe try this instead of mywind
};
}
PeejAvery at 2007-11-8 0:53:23 >
# 12 Re: help with iframes...
but that said 'mywind.document.M' has no props

i tried this :

var hand = mywind.document.getElementById('m');
var d = hand.contentDocument;

if(d==null || d==undefined)
alert('no');
else
alert('yes');

var l =d.getElementsByTagName('hbox');
alert(l.length);

//d.write('india');

this returned 2... which was right for i had 2 dummy hboxes in the mainframe.xul...

but when i said d.write() it says 'd.write()' is not a function...

is there no solution for this :( :(
gsatyaprakash at 2007-11-8 0:54:33 >
# 13 Re: help with iframes...
atlast i could do it !!!!!!!!!

i just removed the src attribute from the iframe tag...
now i cud write to the iframe...

the small change i made was :

<iframe id='m'>
</iframe>

but what in case the src tag is mandatory... like it has it's own design ?
ne ways for now it works...
thank you for all the help...
gsatyaprakash at 2007-11-8 0:55:35 >
# 14 Re: help with iframes...
The iframe has no required attributes. They are all optional.
PeejAvery at 2007-11-8 0:56:30 >