Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2006, 09:01 PM   PM User | #1
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
return client height / width.

i need the innerHeight and innerWidth of the clients browser window to be returned from a function.

here is what i have however some times the value being returned is in fact greater than the browser window (only by a few pixles) i'm assuming this has something to do with 'tabs' in my browser.

Code:
function getW(){
var w;
if(document.innerWidth){ w=document.innerWidth;
} else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
} else if(document.body){ w=document.body.clientWidth; }
return w;
}
function getH(){
var h;
if(document.innerHeight){ h=document.innerHeight;
} else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
} else if(document.body){ h=document.body.clientHeight; }
return h;
}
Edit:
i'm returning the value into a Math.random()*getH();
i'm using the value from that to randomly position a single character on the page.
hope that helps :S
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<
rlemon is offline   Reply With Quote
Old 01-18-2006, 09:25 PM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,292
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
html, body {
margin:0;
padding:0;
border:0;
text-align:center;
}
</style>
<script type="text/javascript">
<!--
function getW(){
var w;
if(document.innerWidth){ w=document.innerWidth;
} else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
} else if(document.body){ w=document.body.clientWidth; }
return w;
}
function getH(){
var h;
if(document.innerHeight){ h=document.innerHeight;
} else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
} else if(document.body){ h=document.body.clientHeight; }
return h;
}
function showMe(){
alert(getH());
alert(getW());
}
//-->
</script>
</head>

<body>
<form action="#" method="post">
<div>
<input type="button" onclick="showMe()" value="Show Me">
</div>
</form>
</body>
</html>
It seems to be returning correctly. IE does have a border on the body so you need to set that to 0 as well. You may want to get this FF extension called MeasureIt which allows you to draw out a ruler in your FF browser. I've attached an SS with an alert and the Ruler drawn. They seem to match.
Attached Thumbnails
Click image for larger version

Name:	height.JPG
Views:	428
Size:	49.6 KB
ID:	4186  
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||

Last edited by _Aerospace_Eng_; 01-18-2006 at 09:27 PM..
_Aerospace_Eng_ is offline   Reply With Quote
Old 01-18-2006, 09:38 PM   PM User | #3
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
Quote:
Originally Posted by _Aerospace_Eng_
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
html, body {
margin:0;
padding:0;
border:0;
text-align:center;
}
</style>
<script type="text/javascript">
<!--
function getW(){
var w;
if(document.innerWidth){ w=document.innerWidth;
} else if(document.documentElement.clientWidth){ w=document.documentElement.clientWidth;
} else if(document.body){ w=document.body.clientWidth; }
return w;
}
function getH(){
var h;
if(document.innerHeight){ h=document.innerHeight;
} else if(document.documentElement.clientHeight){ h=document.documentElement.clientHeight;
} else if(document.body){ h=document.body.clientHeight; }
return h;
}
function showMe(){
alert(getH());
alert(getW());
}
//-->
</script>
</head>

<body>
<form action="#" method="post">
<div>
<input type="button" onclick="showMe()" value="Show Me">
</div>
</form>
</body>
</html>
It seems to be returning correctly. IE does have a border on the body so you need to set that to 0 as well. You may want to get this FF extension called MeasureIt which allows you to draw out a ruler in your FF browser. I've attached an SS with an alert and the Ruler drawn. They seem to match.
ok, that looks nice - however it's still not working for me.


http://rlemon.com/assassins/test <-- characters are randomly scattered on the page - reload a couple times with the browser NOT maximized and you'll see scrollbars occasionally.
__________________
public string ConjunctionJunction(string words, string phrases, string clauses)
{
return (String)(words + phrases + clauses);
}
<--- Was I Helpfull? Let me know ---<
rlemon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:05 PM.


Advertisement
Log in to turn off these ads.