简体   繁体   中英

I need to detect if javascript is enabled or not in asp.net page load in c#

I have tried below code and it is detecting whether current request browser is supports to java script or not only. But my actual requirement is detect particular request browser that whether java script is enabled or disabled by the time request hit the page_load method

var request = HttpContext.Current.Request;
bool jsEnabled = request.Browser.JavaScript;

if (!jsEnabled)
{
    javaScriptEnabled = false;
}

That's not possible, you're using a server side language, it does not access that kind of property when the user executes a request.

The client may provide some meta info through HTTP headers, but they don't necessarily tell you whether the user has JavaScript enabled or not and you can't rely on them anyway.

Source : Check if JavaScript is enabled with PHP

The only way to know it's on the client side using a <noscript></noscript> tag.

Besides , request.Browser.JavaScript tells you if the browser supports javascript, not if it's enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM