检测 ASP.Net 中的移动浏览器是否启用了 JavaScript

发布于 2024-09-30 02:51:41 字数 365 浏览 5 评论 0原文

我想在向用户显示页面之前检查移动浏览器是否启用了 JavaScript。我从研究中发现的代码是:

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

因此,为了确保浏览器上启用了 javascript,您需要检查返回的值是否等于或大于 1。这适用于普通浏览器,但是当我测试它时在我的手机上,无论我的 javascript 启用还是禁用,返回值始终为 0.0。

有没有办法检查移动浏览器是否启用了 JavaScript,或者浏览器是否会自行处理这种情况?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝咒 2024-10-07 02:51:41

我自己也遇到了完全相同的问题。我们最终编写了一小段 JavaScript,它将表单中隐藏变量的值设置为 1,并在欢迎页面上立即回发到服务器,然后将此提示存储在会话中。

这并不美妙,但在所有不同的移动浏览器以及我们发现的不同问题之间,这是我们唯一可以回复的

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

时光匆匆的小流年 2024-10-07 02:51:41

如果您想使用 ASP.NET 来尝试确定这一点,请确保您使用的是最新版本的移动设备浏览器文件。如果没有这个,ASP.NET 对检测移动浏览器的支持非常有限。

但是,检测浏览器支持的唯一可靠方法是在页面上(在浏览器中)进行检测。服务器最多只能知道浏览器是否支持 JavaScript,但不知道用户是否在浏览器设置中关闭了此功能。

在实现移动网络时,您还需要注意不同的浏览器并不实现所有 JavaScritp 功能。这意味着仅仅检测 javascript 可能还不够。您需要测试您想要的单个功能。这绝对是目前任何可用的服务器端设备能力数据库都无法做到的。

当涉及移动网页上的 JavaScript 时,请考虑使用渐进增强。这将有助于确保您的网站可供更多人使用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文