ASM wrote :
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/develop...SFX_Browser.js
This is a very bad file as all of such file relies on user agent string
detection instead of detection object/feature support.
or
<script type="text/javascript">
<!--
Using HTML comments in scripts is not recommendable and not needed.
Don't Use HTML Comments In Script Blocks
http://www.javascripttoolbox.com/bes...ices/#comments
function getCanvasWidth() {
return document.body.clientWidth || innerWidth;
What about IE6 and IE7 in compliant rendering mode? A very wide majority
of users are now using MSIE6 or MSIE7. And a growing minority of web
authors are trying to move toward standards compliance. So giving
recommendations to people should at least start with triggering browsers
into standards compliant rendering mode where HTML and CSS rendering are
more consistent across browsers. Your code is not correct for MSIE6 and
MSIE7 in standards compliant rendering mode. And even in
backward-compatible rendering mode, it should be offsetWidth, not
clientWidth.
}
function getCanvasHeight() {
return document.body.clientHeight || innerHeight;
}
alert('viewport width = '+getCanvasWidth()+' px');
alert('viewport height = '+getCanvasHeight()+' px');
Alerts are always a bad way to communicate values gathered in real time
as they interrupt script flow and unneedlessly makes the user always
click an OK button to close the alert. Using alerts should be avoided.
function getSizes() {
var w = document.body.clientWidth || innerWidth;
var h = document.body.clientHeight || innerHeight;
That's wrong. In backward compatible mode (not even in standards
compliant rendering mode), it must be at least
var h = document.body.offsetHeight || innerHeight;
var W = document.body.clientWidth || outerWidth;
var H = document.body.clientHeight || outerHeight;
Where did you see that document.body.clientHeight is equivalent to the
window's outerHeight?? What your code is submitting and proposing here
is very wrong.
var Sw = screen.width;
var Sh = screen.height;
The last 4 variable have nothing to do with the poster's message.
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;
Well, at least, you could have added
window.onresize = getSizes;
He did say
{
if the user resize the Web Browser's Window,
upon refresh, the webpage will show the width size of the web browser
}
Gérard
--
Using Web Standards in your Web Pages (Updated Dec. 2006)
http://developer.mozilla.org/en/docs...your_Web_Pages