Detect Javascript enabled on server side
I have seen a few ways to detect if javascript is enabled. I have a unique situation. The Global.asax handles all thrown errors
protected void Application_Error(Object sender, EventArgs e)
{
//email develo开发者_运维技巧pment team
}
Recently, I have had issues with people disabled javascript on their machines. These are corporate machines and they are not allowed to do this. I could add some javascript detection to the master page, but I dont know how I can get this into the "catch all" method above.
What can I do to detect if javascript is enabled on the client in this scenerio?
You can Use javascript to change the value of hidden field in the page's onload event.
If you get new value on postback, then javascript is enabled
Well, I don't think you need general js detection for your particular task. I would advise you to add a <noscript>
tag, and put an image into that tag. If anyone requests that image, then you might want to do that error logic you were talking about.
I'll try to find some resource that collaborates that browsers don't fetch what's inside <noscript>
tags if scrips are enabled.
EDIT See this previous stackoverflow post for more info. It's intuitive that this must be true, but it's nice to have more than one opinion behind this.
Oh, I just saw that you were going with the ajax + wait n
seconds approach.I would strongly advise against that, seeing as how you might easily get false positives - this may happen when the user quickly navigates away from the trapped page or some kind of temporary network delay occurs.
And although you are not interested, this approach has the added benefit of graceful degrade. The booby trapped image might as well show the user how to turn scripts on. :)
This gives a thorough explanantaion for what you require
http://www.codeproject.com/KB/aspnet/JavaDetectService.aspx
精彩评论