How to access property of a LAYER within Jscript?

J

José Joye

Hello,
I'm trying to update the size of a layer within my page as soon as the
window is resized. I look at the Jscript ref guide. However, I keep
receiving error when executing the script fired at window resize
(f_resize_bottom()). It tells me that document.layers["layer_bottom"] is
null or not an object.

Any help welcome :)
José

Here is a code snippet:

<html>
<head>
<script>
<!--
function f_resize_bottom()
{
document.layers["layer_bottom"].width=
document.layers["layer_bottom"].window.innerWidth
}
//-->
</script >
</head>

<body onresize=f_resize_bottom()>

<div style="position: absolute; width:100%; height: 43px; z-index: 1000;
left: 2px; top: 200px" id="layer_bottom" name="layer_bottom">
<table border="0" cellpadding="0" cellspacing="0" style="margin-top:
8px" background="../images/fond_bandeau_bleu.gif">
<tr height="35px">
<td width="150" nowrap>
<p class="CRight">© 2004 All rights reserved<br>
My Company</td>
<td width="620"><img border="0" src="../images/bandeau_bleu.gif"
height="35" width="620"></td>
<td width="100%"></td>
</tr>
</table>
</div>
</body>
 
M

Martin Honnen

José Joye wrote:

I'm trying to update the size of a layer within my page as soon as the
window is resized. I look at the Jscript ref guide. However, I keep
receiving error when executing the script fired at window resize
(f_resize_bottom()). It tells me that document.layers["layer_bottom"] is
null or not an object.

document.layers is part of the Netscape 4 object model, that object
doesn't exist in recent Netscape versions (6/7) and neither in any IE
version.
If you want to change the CSS inline settings of an element with a
certain id with IE5+, Netscape 6/7, Opera 7 and other browsers
implementing the W3C DOM try
var element;
if (document.getElementById) {
element = document.getElementById('elementId');
if (element && element.style) {
element.style.width = 440 + 'px';
}
}

As for the body onresize to change the width that shouldn't be necessary
at all if you use static CSS to set
width: 100%;
 
J

José Joye

Thanks for your answer.

This sounds like I'm not using the good reference guide for JavaScript (I'm
using the version 1.3 of Client Script from Netscape).
What will be the correct reference guide to use for writting against new
browser?

As a side note, I was not really trying to update the with of my Layer (this
was just a sample). What I'm hopping to do is to place within a layer a kind
of footer that will stay visible at the end of the window and stay there if
we resize the window or use the scroll bars.

Thanks,
José
Martin Honnen said:
José Joye wrote:

I'm trying to update the size of a layer within my page as soon as the
window is resized. I look at the Jscript ref guide. However, I keep
receiving error when executing the script fired at window resize
(f_resize_bottom()). It tells me that document.layers["layer_bottom"] is
null or not an object.

document.layers is part of the Netscape 4 object model, that object
doesn't exist in recent Netscape versions (6/7) and neither in any IE
version.
If you want to change the CSS inline settings of an element with a
certain id with IE5+, Netscape 6/7, Opera 7 and other browsers
implementing the W3C DOM try
var element;
if (document.getElementById) {
element = document.getElementById('elementId');
if (element && element.style) {
element.style.width = 440 + 'px';
}
}

As for the body onresize to change the width that shouldn't be necessary
at all if you use static CSS to set
width: 100%;
 
M

Martin Honnen

José Joye wrote:

This sounds like I'm not using the good reference guide for JavaScript (I'm
using the version 1.3 of Client Script from Netscape).
What will be the correct reference guide to use for writting against new
browser?

Start with reading the http://jibbering.com/faq/, in particular
http://jibbering.com/faq/#FAQ2_8
and
http://devedge.netscape.com/viewsource/2001/updating-dhtml-web-pages/
As a side note, I was not really trying to update the with of my Layer (this
was just a sample). What I'm hopping to do is to place within a layer a kind
of footer that will stay visible at the end of the window and stay there if
we resize the window or use the scroll bars.

With CSS 2 you can use
position: fixed;
bottom: 100%;
to achieve that without scripting. Mozilla, Netscape 7, Opera 7 should
all support that, only IE on Win doesn't do that.
 
J

José Joye

Thanks for the links. Very nice :)

I'm still having problem to position my DIV element at the bottom of the
window. I spent some time gooooogling and reading doc. However, was not
really successfull. Since the subject is a bit different, I started a new
thread
Positioning a DIV at the bottom of the window (compatible IE and
Opera) - how?


José
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top