2

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 development 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?

4
  • Don't do this on the server, do it on the client. Use <noscript> etc. Commented Jul 18, 2011 at 13:56
  • @Raynos - I want to be emailed if a visitor has javascript disabled. They should get in trouble for this. I do not want to add friendly error messages. Is this practical to accomplish with <noscript>? Commented Jul 18, 2011 at 13:59
  • 1
    @P.Brain.Mackey that should be a IE user setting sysadmin thing. And to detect them just send an ajax message saying "javascript is on" and send yourself an email if you dont get the message within n seconds. As a side-note this is code debt. Redesign your website so it works without javascript. Banning users from turning javascript off is a stupid company policy. Commented Jul 18, 2011 at 14:01
  • @Raynos - ok I see your point. Yes, it will be a sysadmin thing, but the system admins require that I prove that people are doing this before they will spend any time on it. Commented Jul 18, 2011 at 14:03

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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. :)

Comments

1

This gives a thorough explanantaion for what you require

http://www.codeproject.com/KB/aspnet/JavaDetectService.aspx

1 Comment

+1 to both answers. These are helpful. I'm going to go with Raynos solution and use AJAX and detect on the client. @Raynos if you post this as your answer I will mark it as such. It meets all the requirements I asked for and is likely to be more maintainable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.