By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,381 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,381 IT Pros & Developers. It's quick & easy.

Window sizes NN6.x or higher

P: n/a
Hi NG!

A wise man said "You don't have to know anything but where to find it" :)
K I've been searching about two hours but didn't find one thing usable.

I have a layer at my page. In it there's a picture. I want this layer always
to be placed at the middle of the screen.
So I read out the window width and replace the layer. Works fine.

The problem is, that I don't know how to read out window width using NN6.x
or higher. Heres my function:

--------------------------------------------------------------

function Aufloesung()
{

if (document.layers)
{
sw = innerWidth;
sh = innerHeight;
}
else
{
sw = document.body.offsetWidth;
sh = document.body.offsetHeight;
}

if (document.all)
{
ide=document.all["aktuell"];
abstand=(sw-332)/2;
ide.style.left=abstand;
}

if (document.layers)
{
document.layers["aktuell"].pageX=(sw-332)/2;
}

if (document.getElementByID)
{
var ide=document.getElementById("aktuell");
ide.style.left=(sw-332)/2;
}

}

--------------------------------------------------------

IE and NN4.x works fine. But no chance for NN6.x or higher :(
Could some one help me, please? The problem is about to drive me mad :)

Thanx a lot! ...Jochen
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Jochen Califice" <ma**@boomboxx.de> writes:
function Aufloesung()
{

if (document.layers)
{
sw = innerWidth;
sh = innerHeight;

Why only use innerWidth in Netscape 4? Instead of testing for
document.layers (which has nothing to do with innerWidth)
you could test for innerWidth directly:

if (typeof window.innerWidth == "number")

(the prefixed window is important. An undefined variable is an error,
an undefined property has the value "undefined").

You will find that Mozilla (and derivatives like Netscape 6+)
understands innerWidth and innerHeight.
}
else
{
sw = document.body.offsetWidth;


you might mean
document.body.clientWidth
It is more relevant for height, since the body might not take up the
entire viewport.

In some cases it should be
document.documentElement.clientWidth

See <ULR:http://jibbering.com/faq/#FAQ4_9>
You can also center horizontally using CSS:

body {text-align:center; /* because IE5 sucks */}
div {
width:332px;
margin:0px auto;
text-align:left;
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a


Jochen Califice wrote:
Hi NG!

A wise man said "You don't have to know anything but where to find it" :)
K I've been searching about two hours but didn't find one thing usable.

I have a layer at my page. In it there's a picture. I want this layer always
to be placed at the middle of the screen.
So I read out the window width and replace the layer. Works fine.

The problem is, that I don't know how to read out window width using NN6.x
or higher. Heres my function:

--------------------------------------------------------------

function Aufloesung()
{

if (document.layers)
{
sw = innerWidth;
sh = innerHeight;
}
else
{
sw = document.body.offsetWidth;
sh = document.body.offsetHeight;
}


This is the wrong approach, if you check for document.layers then you
can assume Netscape 4, but as your aim is to find the the window
dimensions you should check for the properties
var width, height;
if (typeof window.innerWidth != 'undefined') {
width = window.innerWidth;
height = window.innerHeight;
}
That way you have width and height for all browsers implementing
window.innerWidth (which are at least Netscape 4, Netscape 6/7 and all
Mozilla based browsers.)

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.