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

viewport properties

Sorry if this is in a faq, I don't know where the
faq is... How do I get the x, y, width, and
height of the "viewport"? You know, the viewable
window that may be scrolled. In cross browser fashion,
of course.

Thanks.
Dean Hoover
Jul 23 '05 #1
11 1975
Dean A. Hoover wrote:
Sorry if this is in a faq, I don't know where the
faq is... How do I get the x, y, width, and
height of the "viewport"? You know, the viewable
window that may be scrolled. In cross browser fashion,
of course.

Thanks.
Dean Hoover


The FAQ is here:

http://jibbering.com/faq/

Item 4.9 should get you started...
Jul 23 '05 #2
RobG wrote:
Dean A. Hoover wrote:
Sorry if this is in a faq, I don't know where the
faq is... How do I get the x, y, width, and
height of the "viewport"? You know, the viewable
window that may be scrolled. In cross browser fashion,
of course.

Thanks.
Dean Hoover

The FAQ is here:

http://jibbering.com/faq/

Item 4.9 should get you started...


Thanks. In the combined code for Item 4.9, what does it
mean if the last if statement is false? The variables do
not get defined...

Dean
Jul 23 '05 #3
On Fri, 17 Sep 2004 13:25:25 GMT, Dean A. Hoover <dh*******@yahoo.com>
wrote:

[snip]
Thanks. In the combined code for [FAQ] Item 4.9, what does it mean if
the last if statement is false? The variables do not get defined...


Basically, yes. The variables will exist, but they won't have a value.
However, I don't know how much chance there is of that happening. Most
browsers follow either Microsoft or Netscape with regard to this sort of
proprietary information.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
Michael Winter wrote:
On Fri, 17 Sep 2004 13:25:25 GMT, Dean A. Hoover <dh*******@yahoo.com>
wrote:

[snip]
Thanks. In the combined code for [FAQ] Item 4.9, what does it mean if
the last if statement is false? The variables do not get defined...

Basically, yes. The variables will exist, but they won't have a value.
However, I don't know how much chance there is of that happening. Most
browsers follow either Microsoft or Netscape with regard to this sort
of proprietary information.

Mike

Hmmm. Then maybe I mistyped something. I transcribed the code I
saw in the FAQ, slightly modified it to my liking, and stuffed
it into an HTML page. On IE 6, the variables are undefined. Do
you see what I did wrong? (works on mozilla)

<html>
<head>
<script type="text/javascript">
function x()
{
var winWidth;
var winHeight;

if (typeof window.innerWidth != 'undefined')
{
alert("A");
winWidth = window.innerWidth;
winHeight = window.innerHeight;
}
else
{
alert("B");
if (document.documentElement &&
(typeof document.documentElement.clientWidth != 'undefined') &&
(document.documentElement.clientWidth != 0))
{
alert("C");
winWidth = document.documentElement.clientWidth;
winHeight = document.documentElement.clientHeight;
}
else
{
alert("D");
if (document.body &&
(typeof document.body.clientWidth !=' undefined'))
{
alert("E");
winWidth = document.body.clientWidth;
winHeight = document.body.clientHeight;
}
}
}

window.status = winWidth + "," + winHeight;
}

document.onscroll = x;
x();
</script>
</head>
<body>
<table>
<tr><td><img src="images/spacer.gif" width="500" height="500"></td></tr>
</table>
</body>
</html>
Jul 23 '05 #5
On Fri, 17 Sep 2004 14:11:02 GMT, Dean A. Hoover <dh*******@yahoo.com>
wrote:

[snip]
Hmmm. Then maybe I mistyped something. I transcribed the code I saw in
the FAQ, slightly modified it to my liking, and stuffed it into an HTML
page. On IE 6, the variables are undefined. Do you see what I did wrong?
(works on mozilla)


If what you posted is your exact code, then

(typeof document.body.clientWidth !=' undefined'))

is the problem (from the last nested if statement). You need to remove the
space preceeding "undefined". That is:

(typeof document.body.clientWidth != 'undefined'))

[snip]

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
Thanks. Made that change but its still showing undefined,undefined.
Dean

Michael Winter wrote:
On Fri, 17 Sep 2004 14:11:02 GMT, Dean A. Hoover <dh*******@yahoo.com>
wrote:

[snip]
Hmmm. Then maybe I mistyped something. I transcribed the code I saw
in the FAQ, slightly modified it to my liking, and stuffed it into an
HTML page. On IE 6, the variables are undefined. Do you see what I
did wrong? (works on mozilla)

If what you posted is your exact code, then

(typeof document.body.clientWidth !=' undefined'))

is the problem (from the last nested if statement). You need to remove
the space preceeding "undefined". That is:

(typeof document.body.clientWidth != 'undefined'))

[snip]

Hope that helps,
Mike

Jul 23 '05 #7
On Fri, 17 Sep 2004 14:32:14 GMT, Dean A. Hoover <dh*******@yahoo.com>
wrote:
Thanks. Made that change but its still showing undefined,undefined.


Sorry, I forgot to mention the x() call. In its location, the body of the
document hasn't been loaded, so the dimensions can't be calculated. Call
the function using the load intrinsic event

<body ... onload="x();">

or

window.onload = x;

and everything will be fine.

[snipped top-post]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8
Thanks Mike, that works. Now to figure out what properties
I need to look at to the the "viewport" x,y,width,height, based
on where the browser window is scrolled to... I'm reading
through the O'Reilly Dynamic DHTML book, trying to find the
various ways these scroll properties are referred to.

Thanks.
Dean

Michael Winter wrote:
On Fri, 17 Sep 2004 14:32:14 GMT, Dean A. Hoover <dh*******@yahoo.com>
wrote:
Thanks. Made that change but its still showing undefined,undefined.

Sorry, I forgot to mention the x() call. In its location, the body of
the document hasn't been loaded, so the dimensions can't be calculated.
Call the function using the load intrinsic event

<body ... onload="x();">

or

window.onload = x;

and everything will be fine.

[snipped top-post]

Mike

Jul 23 '05 #9
Dean A. Hoover wrote:
How do I get the x, y, width, and
height of the "viewport"?


You've already been pointed to the FAQ, however the code provided in 4.9
can be inaccurate in some situations; Richard Cornford's been writing a
more advanced version with a very solid logic, and has posted an early
release recently - AIUI it should be added as a FAQ note when the author
is satisfied with his tests.

The original code, which I believe you could be interested using, and a
slight modification later in the thread, can be found there:

<URL:http://groups.google.com/groups?selm=chv12l%24sjs%241%248302bc10%40news.dem on.co.uk>
Regards,
Yep.
Jul 23 '05 #10
JRS: In article <tP***************@twister.nyroc.rr.com>, dated Fri, 17
Sep 2004 00:01:29, seen in news:comp.lang.javascript, Dean A. Hoover
<dh*******@yahoo.com> posted :
Sorry if this is in a faq, I don't know where the
faq is... How do I get the x, y, width, and
height of the "viewport"? You know, the viewable
window that may be scrolled. In cross browser fashion,
of course.


The newsgroup FAQ is posted to the newsgroup three times a week, in two
parts. It is also cited in posters' signatures, and frequently cited
specifically in replies. One should always read a newsgroup for a while
before posting to it.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #11
Excellent information. Thanks for the help!
Dean

Yann-Erwan Perio wrote:
Dean A. Hoover wrote:
How do I get the x, y, width, and
height of the "viewport"?

You've already been pointed to the FAQ, however the code provided in 4.9
can be inaccurate in some situations; Richard Cornford's been writing a
more advanced version with a very solid logic, and has posted an early
release recently - AIUI it should be added as a FAQ note when the author
is satisfied with his tests.

The original code, which I believe you could be interested using, and a
slight modification later in the thread, can be found there:

<URL:http://groups.google.com/groups?selm=chv12l%24sjs%241%248302bc10%40news.dem on.co.uk>

Regards,
Yep.

Jul 23 '05 #12

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

Similar topics

8
by: Warren Post | last post by:
Here's a problem I've never seen before. On <http://snow.prohosting.com/srcopan/anti/>, should the viewport width be less than the width of the page's header, then the right margin becomes stuck...
2
by: tomasio | last post by:
dear group, as nobody answered my recent posts (maybe they were too complicated) i just ask you to help me on a rather simple issue: how can i stretch divs to the full height of the viewport (in...
12
by: Csaba Gabor | last post by:
I'd like to have a pic (.jpg - think Map) on a page and a 'viewport' onto that pic, either of whose sizes I could alter by appropriately dragging the element (using, for example, code from the...
4
by: john | last post by:
Hi to All, I am new to html authoring, so sorry if my terminology is not correct or exact. I would like to position a footer div to the bottom of the browser window. As I research in the web...
0
by: Joel DaBona | last post by:
Hello, I have a DIV with a background image. The height of the parent is 100% and both the HTML and the BODY tag have a 100% height. The DIV is larger than the viewport, but the background...
1
by: Jake Barnes | last post by:
I searched comp.lang.javascript on Google Groups but I didn't find an answer when I searched for "viewport" or "viewport div" or any combination of words using "viewport" so now I think I'm...
6
by: 123shailesh | last post by:
Hello everyone, I need some help. I have been working on it for some time but havent been able to think of any solution. Even had thought of making do without it, even though it was a major part...
3
by: Joel Hedlund | last post by:
Hi! I've raised this issue on #pygtk and #gtk+ but with no luck. I haven't been able to solve this even with aid of google, the pygtk reference and the gtk C source, so pretty please help? ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.