1

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 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
You have to be careful, because many browsers could support this test, but they could not support others features
1

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.

1 Comment

Important Note: This project is no longer supported and will be removed on October 29, 2010, mdbf.codeplex.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.