Window's Width

T

Tweety

Hello,

I need to display the current Web Browser's Width on my web page. I
Tried Screen.width, but it is for the width of the Windows. I tried
Window.width, but it doesn't work.

What i want to do is, if the user resize the Web Browser's Window,
upon refresh, the webpage will show the width size of the web browser
windows. this will help me in working on Floating Menu on my web page.
thanks.
 
A

ASM

Tweety a écrit :
Hello,

I need to display the current Web Browser's Width on my web page. I
Tried Screen.width, but it is for the width of the Windows. I tried
Window.width, but it doesn't work.

you could see that :
http://www.javascript-fx.com/development/javascript/JSFX_Browser.js

or

<script type="text/javascript">
<!--
function getCanvasWidth() {
return document.body.clientWidth || innerWidth;
}
function getCanvasHeight() {
return document.body.clientHeight || innerHeight;
}

alert('viewport width = '+getCanvasWidth()+' px');
alert('viewport height = '+getCanvasHeight()+' px');

function getSizes() {
var w = document.body.clientWidth || innerWidth;
var h = document.body.clientHeight || innerHeight;
var W = document.body.clientWidth || outerWidth;
var H = document.body.clientHeight || outerHeight;
var Sw = screen.width;
var Sh = screen.height;
var d = document.createElement('P');
d.innerHTML = 'View Port : width = '+w+' -- height = '+h+'<br>'+
'Window : width = '+W+' -- height = '+H+'<br>'+
'Screen : width = '+Sw+' -- height = '+Sh;
document.body.appendChild(d);
}

onload = getSizes;

//-->


But all that doesn't mean you'll get the right sizes
(depends of the browser ...)
 
E

Evertjan.

Tweety wrote on 10 mei 2007 in comp.lang.javascript:
I need to display the current Web Browser's Width on my web page. I
Tried Screen.width, but it is for the width of the Windows. I tried
Window.width, but it doesn't work.

What i want to do is, if the user resize the Web Browser's Window,
upon refresh, the webpage will show the width size of the web browser
windows. this will help me in working on Floating Menu on my web page.
thanks.

My browser properties are non of your clientside scripting business under
normal security settings, only the window view plane is.
 
Y

Yun

Tweety wrote :




All you need is to use position: fixed and then set your floating menu
at some position.

E.g.

#FloatingMenu {position: fixed; right: 8%; top: auto;}



"position:fixed" is not supported on IE6, I thought.
 
T

Tweety

Hello Gerard,

I understand what you mean, but the design of the webpage is at the
center. I'll try to use your way.

Thanks Everybody. I'll try tonite and reply on the result tomorrow.
thanks.
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,164
Latest member
quinoxflush
Top