473,389 Members | 1,367 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,389 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 2427
"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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.