Screen resolution

835 views
Skip to first unread message

Pythoni

unread,
Apr 7, 2007, 6:56:21 AM4/7/07
to Django users
For my Django application I need to detect user's screen resolution.
So, I have the script in Javascript

function resolution()
{
var winX = screen.width;
var winY = screen.height;

}
I call the script like this
<form method="post" action="./" enctype="multipart/form-
data"onSubmit="return resolution(this)">

This script finds the resolution but I need to pass the screen
resolution values to my Django application for further processing. How
can it be done?
Or is it a better way than using Javascript?
Thanks
L.

I

Baurzhan Ismagulov

unread,
Apr 7, 2007, 7:55:14 AM4/7/07
to django...@googlegroups.com
Hello Pythoni,

On Sat, Apr 07, 2007 at 03:56:21AM -0700, Pythoni wrote:
> This script finds the resolution but I need to pass the screen
> resolution values to my Django application for further processing. How
> can it be done?
> Or is it a better way than using Javascript?

What about letting your Django application generate the data you need to
present in a device-independent way and then rendering it to a concrete
screen size in a template?

With kind regards,
--
Baurzhan Ismagulov
http://www.kz-easy.com/

Pythoni

unread,
Apr 7, 2007, 9:04:19 AM4/7/07
to Django users

On Apr 7, 1:55 pm, Baurzhan Ismagulov <i...@radix50.net> wrote:
> Hello Pythoni,
>
> On Sat, Apr 07, 2007 at 03:56:21AM -0700, Pythoni wrote:
> > This script finds the resolution but I need to pass the screen
> > resolution values to my Django application for further processing. How
> > can it be done?
> > Or is it a better way than using Javascript?
>
> What about letting your Django application generate the data you need to
> present in a device-independent way and then rendering it to a concrete
> screen size in a template?
>

Thank you for your reply.
I need to allow users to choose their own website background.A user
can choose whatever image he wants.But if a picture is large I need to
make it smaller to fit his screen.
So, I thought that I will find out the screen resolution and according
to it the Django script resize the image to fit the screen.
Or do you have a better idea?
Best regards,
L.

Tim Chase

unread,
Apr 7, 2007, 9:18:10 AM4/7/07
to django...@googlegroups.com


Well, sometimes the browser will send back the browser's screen
info in one of the headers. You might go digging through your
dictionary of headers in request.META for such information.
YMMV. Though there is a difference between the screen-resolution
and the browser's canvas-size. Make sure you're getting the
information you need.

Javascript isn't reliable. You can get folks like me who fly
with JS turned off most of the time (I use the FireFox NoScript
plugin, but I've worked places where IT policy disabled all
scripting for security purposes...you'd be surprised the number
of browser-based exploits that require JS). You can get folks
who resize their screens/browsers between the submission to your
app and the time the response comes back making your information
wrong. You may suggest "this page best viewed at MxN
resolution", but I don't know anybody who actually follows this.
I might have a browser occupying half my screen. I might be
browsing from a mobile with a max-resolution of 320x240. And if
you're trying to do some sort of artistic layout stuff (somewhat
like Tabblo does), it may be accurate on one machine, but they
might browse from another machine and need to have things
re-laid-out.

I'd suggest going with Baurzhan's suggestion of writing portable
HTML/CSS that will adapt to the user's screen size, no matter
what it is. Feel free to decorate with JS functionality, but
don't rely on it or on client-side dimensions.

-tkc


Baurzhan Ismagulov

unread,
Apr 7, 2007, 10:07:31 AM4/7/07
to django...@googlegroups.com
On Sat, Apr 07, 2007 at 06:04:19AM -0700, Pythoni wrote:
> I need to allow users to choose their own website background.A user
> can choose whatever image he wants.But if a picture is large I need to
> make it smaller to fit his screen.
> So, I thought that I will find out the screen resolution and according
> to it the Django script resize the image to fit the screen.

The user has to choose the image from one of your pages and submit that
to your site via another HTTP request, right? I don't know HTML well,
but I guess you should be able to send the screen resolution in that
request as well, look at HTML forms (I remember reading about hidden
fields, don't know whether it helps, though). Of course, you should
think about handling the cases Tim has described, if you care.

If this is not what you want, you'll need to describe a bit of how you
want to handle all this from the user perspective (is it a web page
background or a desktop one, whether "resize" means stretch or crop,
whether you want to use HTML forms and further HTTP requests, etc.).

Reply all
Reply to author
Forward
0 new messages