Connecting Tech Pros Worldwide Forums | Help | Site Map

Using JS to find browser height in IE??

kay.willow@gmail.com
Guest
 
Posts: n/a
#1: Nov 19 '06
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!


Randy Webb
Guest
 
Posts: n/a
#2: Nov 19 '06

re: Using JS to find browser height in IE??


kay.willow@gmail.com said the following on 11/18/2006 8:04 PM:
Quote:
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/
kay.willow@gmail.com
Guest
 
Posts: n/a
#3: Nov 19 '06

re: Using JS to find browser height in IE??


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:
Quote:
kay.willow@gmail.com said the following on 11/18/2006 8:04 PM:
Quote:
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/
Randy Webb
Guest
 
Posts: n/a
#4: Nov 19 '06

re: Using JS to find browser height in IE??


kay.willow@gmail.com said the following on 11/18/2006 9:01 PM:
Quote:
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/
kay.willow@gmail.com
Guest
 
Posts: n/a
#5: Nov 19 '06

re: Using JS to find browser height in IE??


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:
Quote:
kay.willow@gmail.com said the following on 11/18/2006 9:01 PM:
Quote:
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/
janrenters@gmail.com
Guest
 
Posts: n/a
#6: Nov 19 '06

re: Using JS to find browser height in IE??


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.)

Matt Kruse
Guest
 
Posts: n/a
#7: Nov 19 '06

re: Using JS to find browser height in IE??


kay.willow@gmail.com wrote:
Quote:
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


Randy Webb
Guest
 
Posts: n/a
#8: Nov 19 '06

re: Using JS to find browser height in IE??


kay.willow@gmail.com said the following on 11/18/2006 9:56 PM:
Quote:
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/
Randy Webb
Guest
 
Posts: n/a
#9: Nov 19 '06

re: Using JS to find browser height in IE??


janrenters@gmail.com said the following on 11/18/2006 10:09 PM:

Please quote what you are replying to.
Quote:
Also, just so you know -- the script in the FAQ doesn't seem to work
currently.
Hmmm, ok.
Quote:
(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...".
Quote:
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.
Quote:
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/
kay.willow@gmail.com
Guest
 
Posts: n/a
#10: Nov 19 '06

re: Using JS to find browser height in IE??


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:
Quote:
kay.willow@gmail.com wrote:
Quote:
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
kay.willow@gmail.com
Guest
 
Posts: n/a
#11: Nov 19 '06

re: Using JS to find browser height in IE??


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:
Quote:
kay.willow@gmail.com said the following on 11/18/2006 9:56 PM:
Quote:
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/
kay.willow@gmail.com
Guest
 
Posts: n/a
#12: Nov 19 '06

re: Using JS to find browser height in IE??


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:
Quote:
kay.willow@gmail.com wrote:
Quote:
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
kay.willow@gmail.com
Guest
 
Posts: n/a
#13: Nov 19 '06

re: Using JS to find browser height in IE??


"Undefined" being not literally undefined-- it gives us an empty
bracket, no 0, no undefined, nothing.


Randy Webb wrote:
Quote:
kay.willow@gmail.com said the following on 11/18/2006 9:56 PM:
Quote:
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/
Randy Webb
Guest
 
Posts: n/a
#14: Nov 19 '06

re: Using JS to find browser height in IE??


kay.willow@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?
Quote:
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/
Richard Cornford
Guest
 
Posts: n/a
#15: Nov 19 '06

re: Using JS to find browser height in IE??


janrenters@gmail.com wrote:
<snip>
Quote:
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.


Dr J R Stockton
Guest
 
Posts: n/a
#16: Nov 19 '06

re: Using JS to find browser height in IE??


In comp.lang.javascript message
<1163917034.426387.14710@m7g2000cwm.googlegroups.c om>, Sat, 18 Nov 2006
22:17:14, kay.willow@gmail.com wrote:
Quote:
>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.
Closed Thread


Similar JavaScript / Ajax / DHTML bytes