Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

screen.width yes browser.width ???

Status
Not open for further replies.

irate

Programmer
Jan 29, 2001
92
GB
Within javascript i have used browser.width before but i want to know if there is a function similar that will return the width of the actual browser.

ie. when maximised the browser width and screen width will be nearly the same but when the browser is not maximised the different sizes are causing me a problem because the page is a lot thinner that the screen.
 
I have tried to find the same thing, and I couldn't. The best I could do is get the width of the display part of the browser, not including "chrome" and the favorites/seach pane. I gave up.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Oh thats all i need...
How did you get that?

I got a js that shows me the DOM and it has entries for body.clientHeight and body.clientWidth but they don't seem to work.

I also thought of putting the whole document in a <SPAN> and getting the width of that but im not sure how to do it.
 
You can't put the whole document in a span. It's an inline element. You might be able to do it with a div, that's a block element.

In IE I used document.body.clientWidth and document.body.clientHeight. Note that this is ONLY the size of the area where the document is displayed. It does not include any of the window &quot;chrome&quot; or the favorites/search pane.

I think in NS you can use window.outerWidth and window.outerHeight, but I'm not sure they give the same results. Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Ok, great.
I can get the client hight and width to find the center of the displayed page, like so

<HTML>
<HEAD>
<TITLE>
JavaScript Test
</TITLE>
</HEAD>
<BODY>
JavaScript Test.
<P>
<SCRIPT>var swide = screen.width;</SCRIPT>Screen Width :<SCRIPT>document.write(swide)</SCRIPT><BR>
<SCRIPT>var shigh = screen.height;</SCRIPT>Screen Height :<SCRIPT>document.write(shigh)</SCRIPT><BR>
<SCRIPT>var bwide = document.body.clientWidth;</SCRIPT>Browser Display Width :<SCRIPT>document.write(bwide)</SCRIPT><BR>
<SCRIPT>var bhigh = document.body.clientHeight;</SCRIPT>Browser Display Height :<SCRIPT>document.write(bhigh)</SCRIPT><BR>
<P>
<SCRIPT>var bcentw = bwide / 2</SCRIPT><SCRIPT>var bcenth = bhigh / 2</SCRIPT>Center of Page :(<SCRIPT>document.write(bcentw)</SCRIPT>,<SCRIPT>document.write(bcenth)</SCRIPT>)
</BODY>
</HTML>

BUT,
if i resize the window or maximise it i have to refresh the page to alter the variables.
Is there away that i can tell the page to refresh when the window is resized? like onWindowResize or something?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top