views:

52

answers:

3

Hello, how can I replace screen resolution when accessing some site from script? Is it possible to acces such data when own script connects to the server?

A: 

Are you saying that the site is changing its behavior based on what it thinks the user's screen resolution is? That's a) bad behavior, and b) client-side, so done with JavaScript or an ActiveX control or the like.

If you want your script to mimic that, it'll have to interpret the JavaScript, run the ActiveX, or whatever.

Sites don't have their own "screen resolution". They're rendered to whatever size the browser is at. That's part of the beauty of HTML.

Borealid
Nope, the problem is another: site remembers screen resolution of clients. I have to change this resolution. Just imagine that you are writing some script which access some page. And you don't want the page will remember your real resolution.
Ockonal
Again, as I said, a site cannot get the client's screen resolution via HTTP (I mean, other than by asking the user and having them POST their answer). This is only something accessible via client-side scripting. If you don't run the client-side scripts, the site will never know your "resolution" in the first place.
Borealid
+1  A: 

Here is my answer if I understood your question correctly. It is not possible to change screen resolution for a user when he/she accesses your site.

dejavu
It should be noted that resolution can be retrieved via JS with the `screen.height` and `screen.width` values.
mattbasta
A: 

To give a very definitive answer:

  • You cannot change a user's screen resolution via the browser.
  • You cannot retrieve a user's resolution as part of any ordinary HTTP request. (i.e.: in PHP's $_POST superglobal)
  • You can retrieve a user's screen resolution using JavaScript, which can then be passed back to the server via AJAX.

As a best practice, your website should be resolution independent by means of a fixed, fluid, or elastic layout. Changing a user's resolution is a frustrating experience for users and makes a project operate badly.

Keep in mind, also, that many platforms cannot have their resolutions altered. Most mobile devices, embedded platforms, and video game consoles have fixed resolutions. Also, projectors and televisions usually have very specific resolutions at which they function properly, so adjusting the resolution on these devices would likely wreak havoc.

As an alternative to adjusting screen resolution, check out em-driven layout. An em is a unit of measure in CSS that is relative to the current font. This allows you to dynamically adjust the sizing of your layout and its contents by adjusting the font size of the document (a larger font size will increase the pixel-for-pixel sizes of everything else on the page).

It should be noted that adjusting resolution can be accomplished via ActiveX on Windows, but only after multiple security warnings (and it only works on Windows in IE). This should not be attempted under any circumstances.

mattbasta
Thanks for such answer. But I don't need to build site using the resolution! Site uses it for remembering the guest. Can I disable for javascript getting of my resolution?
Ockonal
Wait whoa whoa whoa whoa. You're using the user's resolution as a means of remembering who they are? What if their resolution changes on its own? Or if they attach a second monitor? You can't disable screen resolution changes from the browser, either. A better way to go about this would be to generate a hash based on a secret string and their IP address (using HMAC) and use a Sessions engine in conjunction with cookies. This is why cookies were invented; don't get crazy if you don't have to.
mattbasta
@mattbasta no, no =) I use resolution as one of elements for generating unique hash sum.
Ockonal