473,405 Members | 2,379 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,405 software developers and data experts.

Using JS to find browser height in IE??

Hey, having a javascript problem on this layout-- Everything's going
great, except we want to code it just with divs, and we want this
footer to stay at the bottom of the page, no matter what.

We've looked at a bunch of different resolution detection scripts, but
we don't want resolution -- we want innerHeight/clientHeight, so we can
tell how big the screen size is even when people aren't looking at our
site with their browsers maximized.

But there's something wrong with our script, because while Firefox
likes it fine, IE keeps returning a value of "0" for its height.

We're really stumped! Anyone know what's wrong?

(Some of it is in PHP, some in JavaScript, so you might need to
download one of the files --
http://efiction.incompetentgirl.com/...tra_header.php
..)

You can see the script in action at
http://efiction.incompetentgirl.com/...p?list=authors ,
if you check the sourcecode and look for the second checkRes operation.

Thank you so much!

Nov 19 '06 #1
15 9093
ka********@gmail.com said the following on 11/18/2006 8:04 PM:
Hey, having a javascript problem on this layout-- Everything's going
great, except we want to code it just with divs, and we want this
footer to stay at the bottom of the page, no matter what.

We've looked at a bunch of different resolution detection scripts, but
we don't want resolution -- we want innerHeight/clientHeight, so we can
tell how big the screen size is even when people aren't looking at our
site with their browsers maximized.

But there's something wrong with our script, because while Firefox
likes it fine, IE keeps returning a value of "0" for its height.
Check the group FAQ:

<URL: http://jibbering.com/faq/#FAQ4_9>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #2
I'm not sure which part you wanted me to fix, but we tried changing it
to--

function findPageHeight(){
if (typeof window.innerHeight!='undefined') {
return window.innerHeight;
}
if (document.documentElement && typeof
document.documentElement.clientWidth!='undefined' &&
document.documentElement.clientHeight!=0) {
return document.documentElement.clientHeight;
}
if (document.body && typeof document.body.clientWidth!='undefined') {
return document.body.clientHeight;
}
return (null);
}

--and it didn't work. Any more detailed help you can give would be
appreciated.
Randy Webb wrote:
ka********@gmail.com said the following on 11/18/2006 8:04 PM:
Hey, having a javascript problem on this layout-- Everything's going
great, except we want to code it just with divs, and we want this
footer to stay at the bottom of the page, no matter what.

We've looked at a bunch of different resolution detection scripts, but
we don't want resolution -- we want innerHeight/clientHeight, so we can
tell how big the screen size is even when people aren't looking at our
site with their browsers maximized.

But there's something wrong with our script, because while Firefox
likes it fine, IE keeps returning a value of "0" for its height.

Check the group FAQ:

<URL: http://jibbering.com/faq/#FAQ4_9>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #3
ka********@gmail.com said the following on 11/18/2006 9:01 PM:
I'm not sure which part you wanted me to fix, but we tried changing it
to--

function findPageHeight(){
if (typeof window.innerHeight!='undefined') {
return window.innerHeight;
}
if (document.documentElement && typeof
document.documentElement.clientWidth!='undefined' &&
document.documentElement.clientHeight!=0) {
return document.documentElement.clientHeight;
}
if (document.body && typeof document.body.clientWidth!='undefined') {
return document.body.clientHeight;
}
return (null);
}

--and it didn't work. Any more detailed help you can give would be
appreciated.
This function is not mine, it was written by RobG, but it is known to
work - flawlessly - and comes from the FAQ code.

function findPageHeight(){
var winWidth, winHeight, d=document;
if (typeof window.innerWidth!='undefined') {
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} else if ( d.documentElement
&& typeof d.documentElement.clientWidth!='undefined'
&& d.documentElement.clientWidth!=0 ) {
winWidth = d.documentElement.clientWidth;
winHeight = d.documentElement.clientHeight;
} else if ( d.body
&& typeof d.body.clientWidth!='undefined') {
winWidth = d.body.clientWidth;
winHeight = d.body.clientHeight;
}
alert('winWidth: ' + winWidth
+ '\nwinHeight: ' + winHeight);
}

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #4
Thank you so much for your time, but as you can see, we're trying to
get a return from the code-- we'd like for the height to be something
we can put into a cookie. As you can see, the script we have right now
uses the return to do this, not a variable.

We tried to adapt the FAQ script to what we need, but it isn't working.
Do you have any ideas about how to modify this to work with our script?
Randy Webb wrote:
ka********@gmail.com said the following on 11/18/2006 9:01 PM:
I'm not sure which part you wanted me to fix, but we tried changing it
to--

function findPageHeight(){
if (typeof window.innerHeight!='undefined') {
return window.innerHeight;
}
if (document.documentElement && typeof
document.documentElement.clientWidth!='undefined' &&
document.documentElement.clientHeight!=0) {
return document.documentElement.clientHeight;
}
if (document.body && typeof document.body.clientWidth!='undefined') {
return document.body.clientHeight;
}
return (null);
}

--and it didn't work. Any more detailed help you can give would be
appreciated.

This function is not mine, it was written by RobG, but it is known to
work - flawlessly - and comes from the FAQ code.

function findPageHeight(){
var winWidth, winHeight, d=document;
if (typeof window.innerWidth!='undefined') {
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} else if ( d.documentElement
&& typeof d.documentElement.clientWidth!='undefined'
&& d.documentElement.clientWidth!=0 ) {
winWidth = d.documentElement.clientWidth;
winHeight = d.documentElement.clientHeight;
} else if ( d.body
&& typeof d.body.clientWidth!='undefined') {
winWidth = d.body.clientWidth;
winHeight = d.body.clientHeight;
}
alert('winWidth: ' + winWidth
+ '\nwinHeight: ' + winHeight);
}

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #5
Also, just so you know -- the script in the FAQ doesn't seem to work
currently. (By which I mean, it doesn't appear to work in IE6; not
wholly surprising, since it seems to have been written for IE4, and
back when Netscape and IE were the only browsers on the market.)

As a test, to make sure I could at least get the alert off of that
script (since I can't tell what I'm doing wrong with the above
adaptation), I slipped that snippet of code raw into the header of our
page. If you go to

http://kh.never-wake-up.net/

in IE6, you'll probably see what I did -- a JavaScript alert telling me
that my winWidth and winHeight were both "undefined".

I copy-pasted the script directly, unaltered -- and I'm pretty sure
this isn't what it's supposed to do. :\ (It DOES, however, give me the
correct values in Firefox, FYI.)

Nov 19 '06 #6
ka********@gmail.com wrote:
We've looked at a bunch of different resolution detection scripts, but
we don't want resolution -- we want innerHeight/clientHeight
See Screen.getViewportHeight() at:
http://www.javascripttoolbox.com/lib/util/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 19 '06 #7
ka********@gmail.com said the following on 11/18/2006 9:56 PM:
Thank you so much for your time, but as you can see, we're trying to
get a return from the code-- we'd like for the height to be something
we can put into a cookie. As you can see, the script we have right now
uses the return to do this, not a variable.

We tried to adapt the FAQ script to what we need, but it isn't working.
Do you have any ideas about how to modify this to work with our script?
Change the alert statement to return winHeight and call it something
like this:

var theWinHeight = findPageHeight();

And then save theWinHeight into your cookie.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #8
ja********@gmail.com said the following on 11/18/2006 10:09 PM:

Please quote what you are replying to.
Also, just so you know -- the script in the FAQ doesn't seem to work
currently.
Hmmm, ok.
(By which I mean, it doesn't appear to work in IE6; not
wholly surprising, since it seems to have been written for IE4, and
back when Netscape and IE were the only browsers on the market.)
No, it was not written "back when NS and IE were the only...".
As a test, to make sure I could at least get the alert off of that
script (since I can't tell what I'm doing wrong with the above
adaptation), I slipped that snippet of code raw into the header of our
page. If you go to

http://kh.never-wake-up.net/
Validate your HTML before trying to script it.
in IE6, you'll probably see what I did -- a JavaScript alert telling me
that my winWidth and winHeight were both "undefined".
I don't have IE6 so I don't know.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #9
Thank you for your response, we looked around and gave
screen.getViewportHeight a try. We came up with this code for our
website, but for some reason it's causing an endless loop. Can you tell
us why? We're really at wit's end here.

<script>
screen.getViewportHeight = function() {
if (!window.opera && (!document.compatMode ||
document.compatMode=="CSS1Compat")) {
return document.documentElement.clientHeight;
}
else if (document.compatMode && !window.opera) {
return document.body.clientHeight;
}
}

function writeCookie() {
var today = new Date();
var the_date = new Date("December 31, 2023");
var the_cookie_date = the_date.toGMTString();
var scrnhgt = screen.getViewportHeight();
var the_cookie = "users_res="+ scrnhgt;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie
if (document.cookie) {
location = '<?=$GLOBALS[callget_res_page_name]?>';
}

}

function checkRes(height) {
if (height != scrnhgt) {
writeCookie();
} else {
return true;
}
}
//-->
</script>

Matt Kruse wrote:
ka********@gmail.com wrote:
We've looked at a bunch of different resolution detection scripts, but
we don't want resolution -- we want innerHeight/clientHeight

See Screen.getViewportHeight() at:
http://www.javascripttoolbox.com/lib/util/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 19 '06 #10
Sorry to be so much trouble. IE gives us "undefined" when we use this
code-- Do you have any idea why, or can you offer any further
suggestions?

Thanks again for your time! We appreciate it.
Randy Webb wrote:
ka********@gmail.com said the following on 11/18/2006 9:56 PM:
Thank you so much for your time, but as you can see, we're trying to
get a return from the code-- we'd like for the height to be something
we can put into a cookie. As you can see, the script we have right now
uses the return to do this, not a variable.

We tried to adapt the FAQ script to what we need, but it isn't working.
Do you have any ideas about how to modify this to work with our script?

Change the alert statement to return winHeight and call it something
like this:

var theWinHeight = findPageHeight();

And then save theWinHeight into your cookie.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #11
Ah, there was a PHP error. We fixed it, but it's still not working --
Firefox reports the height correctly and the cookie is working
correctly and it resizes when you refresh -- but IE doesn't give any
response. Not a 0 or an undefined or anything. Any thoughts on why or
what to do?
Matt Kruse wrote:
ka********@gmail.com wrote:
We've looked at a bunch of different resolution detection scripts, but
we don't want resolution -- we want innerHeight/clientHeight

See Screen.getViewportHeight() at:
http://www.javascripttoolbox.com/lib/util/

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 19 '06 #12
"Undefined" being not literally undefined-- it gives us an empty
bracket, no 0, no undefined, nothing.
Randy Webb wrote:
ka********@gmail.com said the following on 11/18/2006 9:56 PM:
Thank you so much for your time, but as you can see, we're trying to
get a return from the code-- we'd like for the height to be something
we can put into a cookie. As you can see, the script we have right now
uses the return to do this, not a variable.

We tried to adapt the FAQ script to what we need, but it isn't working.
Do you have any ideas about how to modify this to work with our script?

Change the alert statement to return winHeight and call it something
like this:

var theWinHeight = findPageHeight();

And then save theWinHeight into your cookie.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #13
ka********@gmail.com said the following on 11/19/2006 1:25 AM:

Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Sorry to be so much trouble. IE gives us "undefined" when we use this
code-- Do you have any idea why, or can you offer any further
suggestions?

Thanks again for your time! We appreciate it.
The code I posted gives the correct dimensions in IE7 when given valid
HTML. You have no DTD in your pages so IE goes into Quirks Mode and what
it does in Quirks Mode is a toss up.

It leaves me to repeat what I said earlier:

Validate your HTML before trying to script it.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 19 '06 #14
ja********@gmail.com wrote:
<snip>
http://kh.never-wake-up.net/

in IE6, you'll probably see what I did -- a JavaScript
alert telling me that my winWidth and winHeight were
both "undefined".
When the page loads in IE a javascript error is generated stating "line
12, Object required" (paraphrased). That line appears to be:- if
(document.body.clientHeight != null) -, which would error as the
function that contains it is first called from inline code within the
HEAD element of the document, and so at a point when the HTML parser has
not yet seen the opening BODY tag, and so the DOM representation of the
document could not have a valid element reference assigned to its -
body - property.

The code you started from included a test for the existence of -
document.body - which you have omitted. That test would avoid the error
but still you will not get any dimensions from - document.body - prior
to its existence, and may not get correct dimensions until after the
document has fully loaded.

Richard.
Nov 19 '06 #15
In comp.lang.javascript message
<11*********************@m7g2000cwm.googlegroups.c om>, Sat, 18 Nov 2006
22:17:14, ka********@gmail.com wrote:
>var the_date = new Date("December 31, 2023");
var the_cookie_date = the_date.toGMTString();

var the_cookie_date = "Sun, 31 Dec 2023 00:00:00 UTC";

is simpler.

Actually, IIRC, standards call for the format
"Wdy, DD-Mon-YY HH:MM:SS GMT"
but the toGMTString format is commonly used.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Nov 19 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: lawrence | last post by:
Under the domain publicpen.com I've several dozen sites in subdiretories, such as www.publicpen.com/honenbeger. I've no trouble with any of these sites. But under one, which I put in yesterday,...
12
by: Mal Ice | last post by:
I am creating an initial index.htm page on which I show some disclaimers and introduction information. In the head section I have Javascript which determines the screen resolution of the client....
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
1
by: a-ok | last post by:
I need to find a layer's height with Javascript. Also, the bottom coordinate of the layer would be nice. Of course it has to work in MSIE, FF, Opera, NN6+ etc. If there are different ways for...
28
by: Christopher Benson-Manica | last post by:
I have the following document, at http://ataru.gomen.org/file/test.html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head>...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I find the size of a browser window?...
1
by: alivip | last post by:
I integrat program to be GUI using Tkinter I try browser direction as you can see # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to...
11
by: shapper | last post by:
Hello, I am displaying an image on a few pages. The image size is 50 px height and 50 px width. In some pages I need the image to be 30x30 px in others 40x40 px and in others 50x50px. Can I...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.