Click to See Complete Forum and Search --> : Detecting new resolution
kasper_hviid
05-30-2003, 07:02 AM
I wanted to reload my site if the user changed resolution. However, it dont work.
In my script i have this:
var width = screen.width;
up = function() {
if (width != screen.width) {
location.reload();
}
}
opdater = function() {
setTimeout('up()', 100);
}
... and my html contains:
<BODY onload="opdater()">
If I comment out the (width != screen.width) , my page will update constantly. So the problem got to be located just about there!
Any suggestions?
- Kasper Hviid
Nevermore
05-30-2003, 07:09 AM
You could just use the onresize event handler to detect a change in the scren size.
kasper_hviid
05-30-2003, 07:28 AM
Yeah, that works ... but I dont want to reload when the user changes the size of his browser-window!
Any other Ideas?
- Kasper Hviid
Nevermore
05-30-2003, 07:29 AM
Depends on exactly what you are trying to do.
kasper_hviid
05-30-2003, 07:35 AM
What I want? I want my script to "know" whenever the user has changed his resolution, and react to that! I hope thats clear enough!
- Kasper Hviid
kasper_hviid
05-30-2003, 09:09 AM
By the way, can anyone explain why my script dont work?
- Kasper Hviid
Nevermore
05-30-2003, 09:36 AM
Why do you need a script to do that? If your page is well designed, it whould work on all resolutions. Perhaps it would be better for you to improve your HTML/CSS rather than try to put some code in to make it look like you did.
kasper_hviid
05-30-2003, 09:46 AM
My script generates CSS after what resolution the user has. This way, a headline will always have the same size.
Is it possible to do that in CSS alone?
- Kasper Hviid
Vladdy
05-30-2003, 09:54 AM
Why do you need the headline to be the same size. How about letting the user decide which size they are most confortable with :rolleyes:
Nevermore
05-30-2003, 09:59 AM
Setting something to be the same size whatever resoltuion is easy in CSS. So is making it be exactly the same proportion of the screen. Would either of those be what you want?
kasper_hviid
05-30-2003, 10:03 AM
That sounds exactly like the thing I wanted! Could you give me some information about how its done?
Nevermore
05-30-2003, 10:05 AM
Which one?
kasper_hviid
05-30-2003, 10:18 AM
Setting something the same size!
Nevermore
05-30-2003, 10:23 AM
To make something exactly the same width and height in pixels, you can do it like this. (Doesn't to be a div, can be an img etc.)
<div style="height:100px; width:300px"><--Contents--!></div>
kasper_hviid
05-30-2003, 10:26 AM
Sorry, I misunderstood you there! What I wanted is to make my headline become larger at highter resolutions!
Nevermore
05-30-2003, 10:31 AM
You can do it as a percentage then. e.g.
<div style="width:60%; height:10%; border:1px solid black;"></div>
(The border is just to let you see the outline of the div.)
kasper_hviid
05-30-2003, 10:33 AM
I will try it out! Thanks for your help!