如何检测更糟糕的浏览器java脚本被禁用 [英] How to detect wether browser java script is disabled

查看:86
本文介绍了如何检测更糟糕的浏览器java脚本被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

高科技极客,



我有一个小的要求来检测在ac#(。Net Application)中启用或禁用的客户端浏览器javascript这是一个常见的要求在这些日子里,在一个网络应用程序中。



我在google上搜索了我的问题的解决方案,并在下面的解决方案中找到了解决方案但这些问题有待实现 -



1.使用< no script =>标签是在互联网上找到的常见答案,但问题是它不适用于Mozilla和其他浏览器



2.使用以下代码 -



Hi tech geeks,

I have a small requirement to detect the client browser javascript enabled or disabled in a c#(.Net Application) which is a common requirement in these days in a web application.

I have searched a lot for the solution of my question on google and found below solution but these have some issues to get implemented-

1. Using <no script=""> tag is the common answer found on internet but the issue is that it does not works on mozilla and other browsers

2. Using the below code-

protected void Page_Load(object sender, EventArgs e)
      {
          if (Session["JSChecked"] == null && Request.QueryString["JScript"] == null)
          //if (Session["JSChecked"] == null)
          {
              Session["JSChecked"] = "Checked";
              string path = Request.Url + "?JScript=1";
              Page.ClientScript.RegisterStartupScript(this.GetType(), "redirect",
                "window.location.href='" + path + "';", true);
          }
          if (Request.QueryString["JScript"] == null)
              Response.Write("JavaScript is not enabled.");
          else
              Response.Write("JavaScript is enabled.");
          Session.Abandon();
      }





上面代码背后的逻辑是重定向到同一页面并使用javascript传递查询字符串来自代码的代码,如果浏览器的javascript被启用,页面将再次被调用,因此我们可以知道javascript是打开还是关闭。



但问题在于这段代码是页面需要加载两次,这根本不是检测的好方法所以我想要任何其他可以检测浏览器java脚本的解决方案。

但是我看过gmail网站当我们禁用浏览器js时,它不会打开并重定向到另一个页面,说启用浏览器js

我想要与Google相同的功能。



请帮助任何人?



the logic behind the above code is redirecting to same page and passing query string using a javascript code from code behind and if the javascript of browser is enabled the page will be called again and hence we can know whether javascript is on or off.

But the issue in this code is that the page is needed to load twice which is not at all a good way to detect so so i want any other solution which can detect the browser java script .
However i have seen gmail website when we make browser js disabled it does not open and redirects to another page saying to enable browser js
I want the same functionality to that of Google.

Please help any one?

推荐答案

通过检查页面中的+ type =text / javascriptlanguage =Javascript标签响应,你可以发现JS是否在页面中使用。
By checking the + type="text/javascript" language="Javascript" tag in the page response, you can find JS is used in the page or not.


http://stackoverflow.com/questions/121203/how-to-detect-if-javascript-is -disabled [ ^ ]



使用用户控件检查是否从服务器端启用了JavaScript [ ^ ]


这篇关于如何检测更糟糕的浏览器java脚本被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆