How To Check Is JavaScript Enabled
To find out is JavaScript enabled in client's web browser, you must try to execute some JavaScript code. Simply, if client side JavaScript code is executed, then JavaScript is enabled :). After that, you can send that information back to server and deal with it. One of possible solutions is like this:
[ C# ]
protected
void Page_Load(object
sender, EventArgs e)
{
bool JavaScriptEnabled;
if (Session["JavaScriptChecked"]
== null)
{
Session["JavaScriptChecked"]
= true;
// call page again, but with CheckJavaScript=1 in
query string
Page.ClientScript.RegisterStartupScript(this.GetType(),
"redirect",
"window.location.href='" + Request.Url +
"?CheckJavaScript=1" +
"';", true);
}
if (Request.QueryString["CheckJavaScript"]
== null)
JavaScriptEnabled = false;
else
JavaScriptEnabled = true;
}
[ VB.NET ]
Protected
Sub Page_Load(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles
Me.Load
Dim JavaScriptEnabled
As Boolean
If Session("JavaScriptChecked")
= Nothing Then
Session("JavaScriptChecked")
= True
' call page again, but with CheckJavaScript=1 in query
string
Page.ClientScript.RegisterStartupScript(Me.GetType(),
"redirect", _
"window.location.href='" &
Request.Url.ToString() & _
"?CheckJavaScript=1" &
"';", True)
End If
If Request.QueryString("CheckJavaScript")
= Nothing Then
JavaScriptEnabled
= False
Else
JavaScriptEnabled
= True
End If
End
Sub
Related articles:
1. Client Side Script Debugging in ASP.NET