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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browser window size. 1

Status
Not open for further replies.

vasilek

Programmer
Jan 5, 2003
99
US
How to get browser window size? I know Screen object identifies screen width and height, but it doesn't serve the purpose of what I am doing. I need to know the browser window size, because when it minimized some of the elements of the page get shifted aside. Thank you.
 
screen.width and screen.height should help out.
if the resolution is set to say 800*600 then
var Swidth = screenwidth
//output = 600
var Sheight = screen.height
//output = 800 _______________________________________________
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
um.. OK, those are backwards. [lol] long day _______________________________________________
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
Thank you for the reply. I did that - not the case here. JS writes an image on x=500;y=0 position (resolution (800x600). When I make the browser window smaller (resolution stays 800x600) the image is behind the window. I was thinking of getting a browser window width and make an X of the image changing to together with it. Do you have any other ideas?
 
ya, should have yelled at me for not reading your ? more closly sense I said exactly what you said wouldn't work. [smile]

I'm not sure you can dynamically change the image position as you want though. the event of a viewer having their window per say half the screen is not really a event and I'm not sure there is a way to catch that.

possibly someone else has done this, sorry _______________________________________________
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
wait, now I know I'm tired.
you may possibly be able to use window.innerWidth and window.innerHeight
I still not sure on the event of after the page wax loaded but this may become another option

check here link is actually fairly good. great info on browser compatiblity etc..


_______________________________________________
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
You can only set window.innerWidth and window.innerHeight. It doesn't get parameters of the window.
 
hi vasilek
did you check out the link.
innerWidth etc. does return a value in NN!
try them out
<html>
<body>
<script language=&quot;javascript&quot;>
//tested in NN and recieved 1014*605
var myWidth = window.innerWidth;
var myHeight = window.innerHeight;

//tested IE 6.0 1024* res and recieved 995*587 for width output
//var myWidth = document.body.clientWidth;
//var myHeight = document.body.clientHeight;
alert(myWidth +&quot; &quot;+myHeight);
</script>
</body>
</html> _______________________________________________
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
taht was a test in NN 6.2 also
both I should ahve stated in 1024* resolution

if nothing this is some good information I think for the shear fact it goes to remind everyone the difference in what a certain resolution really gives you in deifferent browsers. thus reminding us to remember to test in various browsers. not sure how these would work in opera or others. anyone give them a try?
no resources here for that test _______________________________________________
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
It does work. I tested window.innerWidth in IE6.0 and it was not working. Didn't do any testings on NN. Now tested document.body.clientWidth in IE6.0 and it worked.

Thanks a lot for you expertise.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top