开发者

Detecting if JavaScript is enabled on a Mobile browser in ASP.Net

开发者 https://www.devze.com 2023-01-22 18:17 出处:网络
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:

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 开发者_如何学Gothe 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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消