Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

netscape question :( 1

Status
Not open for further replies.

twist

Programmer
Dec 4, 2001
100
CA
anyone know how to use write() (or anything like it) to add a child div to an already existing div in netscape (under 6) and then be able to access it through js?

i've tried...
document[parentDiv].document.open()
document[parentDiv].document.write(&quot;<div id=\&quot;childDiv\&quot;></div>&quot;)
document[parentDiv].document.close()

it works fine to add the div but i can't access it through...

document.parentDiv.document.childDiv

anyone got any ideas?
thanks in advance, Twist.
 
U should acces the new div like others objects in page:
document.childDiv
________
George, M
 
that won't work with a nested div in netscape. each div has its own document object.
 
Then u must try the way i use for IE4+ and for NS6+
myChildDiv=document.getElementById('childDiv')
This should work it works for me. ________
George, M
 
it already works in ie4+ and ns6+ :p
the problem is netscape 4.7 or so won't pick up divs added after the page has loaded. curse that crappy browser.

thanks for trying though, much appreciated.
 
netscrap 4x:

divs - noway; layers - do-able..
(i've wrote this yesterday, i guess.. well, i'm not lasy to repeat: training, practice :))

var _newObjLayer=new Layer(400,&quot;CurrentLayer&quot;);
//400 - new layer's width
//&quot;CurrentLayer&quot; - the existing layer's name/id; if new layer is not supposed to be nested(sp?) - use window instead..

there are few scripts on , called &quot;hier menus&quot; there you could find a way of creating layers for netscrap in action..
there're its own tricks..

NETSCAPE makes us stronger!! ('n wiser) :)))
Victor
 
thank you very much vituz, not quite what i wanted to hear (darn netscape) but helpful.
 
The above script with the 'new Layer(400, &quot;CurrentLayer&quot;)' will work just fine, but you won't be able to reference it by 'document.CurrentLayer.document.childDiv'.
However, it is possible to create such a refference!
Just use this javascript:

function createLayer(newLayerName, parentLayerName, innerHTML) {
var createLayerFunc = parentLayerName + '.document.' + newLayerName + '=writeLayer(&quot;' + parentLayerName + '&quot;, &quot;' + innerHTML + '&quot;)';
eval(createLayerFunc);
}
function writeLayer(parentLayerName, innerHTML) {
var parentLayer = eval(parentLayerName);
var newLayer = new Layer(100, parentLayer);
newLayer.document.open();
newLayer.document.write(innerHTML);
newLayer.document.close();
newLayer.visibility = 'show';
resizeLayer(parentLayer, newLayer);
return newLayer;
}
function resizeLayer(parentLayer, newLayer) {
newLayer.left = 0;
newLayer.top = parentLayer.document.height;
if(parentLayer.clip.width < newLayer.document.width) {
parentLayer.clip.width = newLayer.document.width;
}
parentLayer.clip.height += newLayer.document.height;
}


If you have a document with a layer (div) called 'div1', after calling the function:

createLayer('div2', 'document.div1', 'This is div2');

you should be able to get a refference to 'div2' (with 'This is div2' as content) by using:

'document.div1.document.div2'.

Success,

Raver1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top