views:

29

answers:

3

I want to check if a mobile browser has javascript enabled before displaying a page to the user. The code I've found from my research is:

System.Web.HttpBrowserCapabilities browser = Request.Browser;
Response.Write(browser.EcmaScriptVersion.ToString());

So to ensure that javascript is enabled on a browser, you need to check wheather the returned valued is either equal to or bigger than 1. This works on normal browsers, but when I test it on my phone the returned value is always 0.0, no matter if my javascript is enabled or disabled.

Is there a way to check if javascript is enabled on a mobile browser or will the browser handle the incapability on it's own?

+2  A: 

I had the exact same problem myself. We ended up writing a small piece of javascript that would set the value of a hidden variable in a form to 1, and post back to the server right away on a welcome page, and then stored this hint in the session.

its not fantastic, but between all the different mobile browsers, and the different issues we found with them, it was the only one we could reply upon

jasper
That sounds like a logical plan to me. If the value is 1 it's enabled, else it couldnt do the change and javascript is disabled. Let me try it out and get back to you on it.
Yo Momma
A: 

try http://wurfl.sourceforge.net/

nLL
A: 

If you want to use ASP.NET to try and determine this, make sure you are using the latest version of the Mobile Device Browser File. Without this, ASP.NET has very limited support for detecting mobile browsers.

However, the only reliable way to detect for browser support is to do it on the page (in the browser). THe best the server could tell would be if the browser has support for JavaScript but would not know if the user had turned this off in browser settings.

When implementing for the mobile web you'll also need to be aware that different browsers don't implement all JavaScritp functionality. This means that simply deteccting javascript may not be enough. You need to test for the individual functionality you're after. This definitely can't be done by any currently available server side device capability database.

Look to use progressive enhancement when it come to JavaScript on mobile web pages. This will help ensure that your site will be usable by more people.

Matt Lacey