How do I make a webpage display what platform and browser its being viewed in? - language-agnostic

I need a webpage to display if its being viewed on a PC/Mac, iphone, etc and also what browser its being run on. Anyone know how I would go about doing that?

You typically get this information through the User-agent: HTTP header sent by your browser. If you were using PHP, you'd get this by reading $_SERVER['HTTP_USER_AGENT']. PHP also has a higher level [get_browser][1] API to read this data.
If you're using another scripting language in your web app, you'll need to look up the equivalent.

You can do it using server-side code if the page is dynamically generated. For example, if you're using PHP you can use the get_browser() function. Other language should have similar capabilities, via the User-Agent header sent by the browser.
You can also do it client-side in Javascript. Some details on this process can be found here: http://www.quirksmode.org/js/detect.html

I think this is what you need!
http://plugins.jquery.com/plugin-tags/useragent
http://jasonlau.biz/userinfo/test1.html

The easiest way is to use Javascript, and the easiest way to use Javascript is to use a library like jQuery. jQuery has .browser detection flags that'll give you what you're looking for.
jQuery.support: browser-specific CAPABILITIES (preferred)
jQuery.browser: browser identity (deprecated)
NOTES:
You can try to determine "browser type" on either the client (web browser) or the server (e.g. IIS or Apache; in .Net or PHP).
Simply reading "browser type" (e.g. from an http return variable) is quite often inaccurate. A better strategy is to "probe" for browser type, using different heuristics. jQuery simplifies this for you.
A better strategy still is to determine browser CAPABILITIES, rather than "browser type". jQuery simplifies this, too.
'Hope that helps!

Related

How-To support Internationalization of JQuery Mobile Offline Web App (i18n)?

I am looking for a general mechanism to internationalize web application that have to work in offline mode.
Initially I was considering adding data-i18n tags to elements but this seems like a very ugly solution.
I came across http://panacodalabs.github.com/The-M-Docs/#components_&_utilities/m_i18n however I do not wish (or can due to time constrains) port my application to that framework.
I need a HTML5 jQuery Mobile friendly solution to this issue, that works in offline mode.
It seems to me that this crucial component is missing on the HTML5 framework.
I wouldn't necessarily say this is a feature JQM should provide, because this is probably done best with some server side logic.
there would be two ways I can think of doing this:
1. have all your language translations in some standalone js files, which you would have to include in manifest file. check the datebox plugin to see how this could be done ( top right - options).
2. create a local database and store translations in the required languages there.
i think the first one should be easier to handle, but probably harder to setup/maintain. also, depending on the amount of translations, js files do become large...
Have you looked at the jQuery i18n plugin?
http://recursive-design.com/projects/jquery-i18n/
I'm currently using it with jQuery 1.7.1 and jQuery Mobile 1.1.0, and it works perfectly.

Does J2ME support HTML5?

I want to make an application for J2ME phones.
In that application I want to use HTML5,
how I can do this?
I worked on LWUIT. Does LWUIT support HTML5?
Or give me any other browser info.
LWUIT/Codename One support HTML5 but not on J2ME.
There's no built-in HTML5 (or any HTML version, for that matter) parser or renderer in J2ME. There's some sort of HTML viewer support in the LWUIT library, but I suspect it is reasonably limited in general, and also in particular regarding specifically HTML5 support. In any case, research LWUIT and see if it is enough for your needs or not (hard to say without knowing your real/actual requirements).
It is also not very practical to write your own HTML parser and renderer (especially if you also need to be able to handle CSS and JavaScript). In essence, you'd have to write your own complete web browser in J2ME.
You can, of course, use platformRequest() to launch the default browser, but not that many mobile phones have HTML5 support yet.
If you also manage the server-side (where the HTML5 pages come from), and all you really need is the data, then write the server code to return/send the data to your J2ME MIDlet as either XML or JSON, which are much easier to handle.

Can you detect the HTML 5 History API on the server side?

Is there reliable a way to detect such browser capability from the user agent string?
HTML5 isn't a server-side language.
Anyway, there isn't a way to reliably detect UA capabilities, for instance they could have Javascript turned off, addons installed, etc. etc.
You could use some SS methods such as PHP's Browser Detect, but aside from that there's nothing more you can really do. This is not at all comprehensive at all, though!
Everything such as this should really be done client side in Javascript, as you can easily detect what's available and what isn't. There's a number of libraries out there that will do this, but it's very simple to do yourself if you know what you want so using one shouldn't really be required. Furthermore, you should never want to do this based on User Agent strings, as I mentioned before there's addons available that can modify behaviour etc. You should literally just check for the feature you wish to use rather than restricting yourself to a certain version of the browser.
Not reliably — you’re stuck with figuring out the browser version from the user-agent string, and maintaining a list of which browser versions support the API.
You could, however, detect it on the client side using JavaScript:
Modernizr
Mark Pilgrim’s suggested History API detection code
and then do a redirect via JavaScript (i.e. by setting window.location) to let the server know whether the API is available or not. That would be the usual way to redirect to a URL starting with # (as per your comment on rudi_visser’s answer.
This is not server side (so it probably does not answer your question, I thought it would be helpful though):
Have you looked at Modernizr
It is a javascript file you include in your HTML page. You can then use its properties to detect if a particular HTML 5 tag is supported by the browser.

How to upload a file to a website using HTML

I'm developing a website and I'd like the users be able to upload files to the server using a webpage.
The server side is .NET, but it's not ASP.NET. That means, I'm generating the html code myself instead using ASP.NET, and I'm working with the GET string and POST stream directly. It's a good exercise to learn what happens under the hood :D, specially nowadays when there is a framework for everything.
I've been trying to find information about this, but I found several approaches, some of them javascript (thing I want to avoid for the time being) and lots of premade controls. What I want is to do it myself, I don't care if there is a nice, nifty and well-proven ASP.NET control... what I want is understand how it do that with all its implications.
Cheers!
In the HTML you need a form with an input of type="file" and the enctype attribute of the form set to "multipart/form-data" rather than the default of "application/x-www-form-urlencoded".
Multipart/form-data is defined in RFC 2388, and will behave differently to the application/x-www-form-urlencoded you've been parsing with this experiment so far, though it's quite straight-forward. The RFC should give you all you need to know to replicate how the HttpRequest.Files property works in ASP.NET.
An extension of this, try sending streams from XMLHttpRequest in a page or HttpWebRequest in a .NET client application, using both POST and PUT (you may have to change IIS settings to allow the PUT through), as this the overlap of working on that along with your experiments here will cover some knowledge that has some real applicability even when you are using all the toolkits. Another extension is to try implementing both sides of both schemes in RFC2617 without any help from the framework (sometimes the server side of this is genuinely useful).
Kudos for experimenting with this, it should bring real experience to back up what you can learn from reading RFC 2616 (though that's still absolutely vital for anyone doing web stuff to be intimiately familiar with, as reading will cover some cases your experiments don't touch on, and explain anything that seems strange in your results).
I think this should have what you need.
Basically you need an <input type="file"> and to set the encoding of your form to multipart/form-data.
<input type="file" name="somename" size="n">
You put that in a form, and hasta la vista baby !
You can't do a file upload using pure HTML: You will need to handle the uploaded files on server side.
You could parse the uploaded file(s) out of the raw POST data if you want to learn how it works "under the hood" (see here for an example how to do it in ASP), but you will need some kind of server side language to do it.

Modify Google Chrome or Mozilla Firefox display settings

I would like to know if it is possible to modify Chrome or Firefox display settings, so that it would only show rectangles of HTML DOM objects? What I want to do is to decrease rendering engine job amount as much as possible, so it would only build layout of the page.
People usually refer to this mode of operation as "headless" (i.e. without UI).
Usually there's an additional requirement - to be able to run it server-side without the usual for client software installed. If you're running it client-side, I wouldn't bother about optimization, it shouldn't give you a big win anyway.
Otherwise, try searching using that term. I've seen it asked for several times, but haven't seen a working out-of-box solution.
[edit] just saw http://hg.mozilla.org/incubator/offscreen, which seems to be a headless version of Mozilla.
I wouldn't go as low-level as modifying the renderer. Instead, I suggest you use Firefox's Greasemonkey to replace the elements from the page with whatever it is you need. You'll need to know a bit of JavaScript, but it's not that hard.
However, this will only work on client side. If you want to do this on server-side ( so that it will work on any page a user requests through your own ), my guess is you'll need to grab the page's content in a string, and then modify it using a HTML parser.