View Full Version : Java Script Newbie needs help!
mark wills
09-07-2002, 06:45 PM
Hi there (1st post - forgive me!)
I need some help - I know very little about client side languages, but I'm an experienced ASP programmer.
I need to find the horizontal resolution of the users screen, and, somehow get it back to the server... I am thinking that I could use Java Script, on the client side, to create a cookie, that could be read by the server...? Can I do this?
I need the server to know, because some ASP is generating horizontal rows of 64x64 icons, and, depending on the screen resolution, I want to write a different number of icons per row.
If anyone can suggest how this can be done, I'd be grateful.
Regards,
Mark.
joh6nn
09-07-2002, 07:43 PM
you can use screen.availWidth; to find out how much available horizontal space there is, and then use document.cookie = "horizontal=" screen.availWidth; which would create a cookie named horizontal, holding the number of pixels you've got to work with.
adios
09-08-2002, 04:01 AM
I'd try something like this:
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
function send_res() {
var H_res = (window.screen) ? screen.width : null;
document.upload.H_res.value = H_res;
document.upload.submit();
}
onload = send_res;
</script>
</head>
<body>
<form name="upload" action="blah.asp" method="post" target="dummy">
<input name="H_res" type="hidden">
</form>
<iframe name="dummy" style="display:none;"></iframe>
</body>
</html>
This should post the data without disturbing the rest of the document. screen.width is essentially the same as .availWidth - it's .availHeight that tends to vary (taskbar, etc.).
realisis
09-08-2002, 08:36 AM
adios wrote: "- it's .availHeight that tends to vary (taskbar, etc.)."
not on my desktop! I position the windows toolbar vertically on the right... ;^]
...
Anyway, wouldn't it be better in this case to sniff out the browser's window width, rather than availWidth? There's no guarantee users will necessarily have their browsers maxed is there?
IE = document.body.clientWidth
NS = self.innerWidth
PS: Opera responds to both.
gmorphus
09-08-2002, 02:26 PM
The first thing I want to say is that it was a good question.
The next thing is that you should write a subject like:
"Newbie needs help!"
it is realy annoying. Use a descriptive subject such as: "sending screen dimensions to the server" or something like that.
Cheers.
Graeme Hackston
09-08-2002, 02:47 PM
IE = document.body.clientWidth
Only if IE is in quirks mode. With a strict doctype It needs document.documentElement.clientWidth
I think this covers most of the bases:
<html>
<head>
<title></title>
<script>
function iw() {
if (window.innerWidth) {
w = window.innerWidth
} else if (document.documentElement && document.documentElement.clientWidth) {
w = document.documentElement.clientWidth
} else if (document.body) {
w = document.body.clientWidth
}
return w;
return null;
}
onload = function() {
alert(iw())
}
</script>
</head>
<body>
</body>
</html>
<edit>this is for window width, not screen width</edit>
realisis
09-09-2002, 05:50 PM
Graeme,
I haven't yet worked with strict doctypes, and in fact wasn't aware IE would behave differently in this instance.
I'll be looking into documentElement sooner than later. Thanks for the pointer.
Graeme Hackston
09-10-2002, 01:01 AM
From what I've found it "sort of" works using document.body.clientWidth making it fun to figure out.
I've also found IE and Mozilla need body{height:100%;} for some DHTML and have read of a few other javascript coding issues.
realisis
09-10-2002, 02:33 AM
"IE and Mozilla need body{height:100%;} for some DHTML body{height:100%;} "
yes, the same is true of Opera I've noticed.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.