Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when JavaScript is disabled in ASP.NET

In the Render method of an ASP.NET web-control, I need to alter the output of the Html based on whether JavaScript is enabled or disabled on the clients browser,

Does anyone know the right incantation to figure that out?

like image 675
Kieron Avatar asked Oct 29 '08 11:10

Kieron


2 Answers

The problem with using script to check whether javascript is enabled is that you only find that out after the script hasn't run.

Some solutions try the opposite - they use javascript to set a value and then supply Javascript enabled controls if that value is later detected. However, this fails with javascript-sometimes-enabled tools like the Firefox NoScript plugin.

A more robust solution is to always send the plain-HTML compatible control, and then have javascript run on page load to add the correct event handlers/extra DOM elements/etc.

However I don't know how this fits in with the ASP.NET approach takes to controls.

like image 109
Gareth Avatar answered Sep 24 '22 15:09

Gareth


The noscript tag is used to define an alternate content (text) if a script is NOT executed.

EDIT: Hi Kieron, take a look at this link: Creating a Server Control for JavaScript Testing, and Detect if JavaScript is enabled in ASPX

like image 34
Galwegian Avatar answered Sep 23 '22 15:09

Galwegian