473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Window sizes NN6.x or higher

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
2 2428
"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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
29
by: wayne | last post by:
Hey there... I'm having some problems passing url parameters with an open.window command. I'm not terribly familiar with java script but here is the code below. When executed it opens the...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
35
by: eyoung | last post by:
I call a function that takes the unit price and quantity ordered to create an amount...it looks something like this. function calculateCost() { quantity=document.RFO.quantity.value;...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.