views:

126

answers:

4

This sounds like a stupid question (to me), but I've searched and I can't find anywhere that seems to talk about it. Where is the media type for an agent set - is it hard-coded by the browser (or whatever) or is this configurable (specifically, IE)?

I ask because I am writing a web app that will be mostly used by normal PCs, but there will be some netbooks using it too. However these netbooks will be running XP, and that seems to be detected as a normal windows browser, however for certain pages I want them to use different CSS (mainly for larger font types), so I was hoping to set them up to be handheld devices and then hit that on my CSS for the appropriate pages (the users that have them will also log on from normal PCs, so detecting type by user isn't an option).

Or is there a better/more correct way of doing this?

Cheers

MH

A: 

Generally, serving the pages based on user agent is handled by the web application web server or rarely by some javascript. If you list the language/framework you are using, more help can come.

Changing the user agent screen on the clients is a generally not good idea. Design your css to be scalable and allow for zooming.

Daniel A. White
+1  A: 

The simplest way would be to detect the user's screen resolution using Javascript: screen.width and screen.height. If it's too small, take appropriate action, like using your mobile stylesheet instead. There isn't a way to detect the exact device a person is using.

DisgruntledGoat
A: 

The HTTP Header's "User-Agent" is how a browser 'tells' the web server what type of browser it is. It can contain operating system and version as well. Under most usual conditions, these values are correct indication. We can make use of this information to churn out suitable html/css that suits the browser (i.e. mobile device, IE6 etc) at the server-side.

Some frameworks e.g. ASP.NET have some form of browser-capability feature to "adapt" the html output (I'm not convinced though).

I cannot think of a better way to do otherwise. For screen size detection, javascript detection should work well, but that doesn't give you much in terms of layout and font-size unless you have some form of implementation that can render the output in an AJAX manner. Couldn be pretty complex.

Not much of an answer here, just hope it can facilitate more ideas.

o.k.w
A: 

I'm working in ASP.NET, making the CSS zoomable isn't an option - most of the screens are going to be fine as-is, but for one screen the layout will need to be different on the netbooks so in that case the users would have to zoom in for one page, then out again for others and, obviously, that isn't a good solution (plus the actual CSS will be different, rather then just the zoom level - only certain elements' fonts will be enlarged, for example). The problem is that the clients will be seen as "normal" windows clients - Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3) (in case anyone is wondering, the Trident part is just IE8 saying that it's IE8 if it's masquerading as IE7) so I will need to change the way the clients present themselves. The easiest (in theory) way to do this would be the configure them as a different media type so they will automatically load the correct CSS with no server-side action necessary, but it's just knowing how to do this.

Again, in theory, I would be very surprised if this isn't possible, or it would make properly testing different media types a nightmare unless you had actual devices available and to-hand, but looking online it seems that this is the case (surely someone would have put an option in the browsers somewhere, where you could set up the media types it supported????).

Mad Halfling