最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Check if Javascript is enabled server side ASP.NET - Stack Overflow

programmeradmin6浏览0评论

Is it possible to check if the client browser has javascript enabled from ASP.NET code?

I was hoping to ideally do this on PreRender of controls, or PageLoad, so that I can change how they look.

Any suggestions, work arounds etc would be much appreciated.

Is it possible to check if the client browser has javascript enabled from ASP.NET code?

I was hoping to ideally do this on PreRender of controls, or PageLoad, so that I can change how they look.

Any suggestions, work arounds etc would be much appreciated.

Share Improve this question asked Jun 4, 2009 at 15:00 FerminFermin 36.1k21 gold badges86 silver badges131 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 7

You can't do it, without making a subsequent request I'm afraid.

There are explanations that can be found by doing a search on Google most use an AJAX call or a hidden field that gets popluated via some javascript, that won't get run if Javascript is disabled.

If you have to do it then I'd try doing it on the very first request from the client, and save a cookie (or somethign similar), then check the value of the cookie on subsequent requests. This assumes that the user doesn't enable / disable Javascript often. You could also store a value in the session.

I hope that helps

Page.Request.Browser.EcmaScriptVersion will indicate what ASP.NET thinks is true. This assumes that the BrowserCaps are correct. It does give you a first pass indication which is probably pretty close.

EDIT: I initially misunderstood the question (enabled vs. supported). You could use the BrowserCaps server side to weed out those UserAgents that don't support JavaScript. Then use one line of script on each request to determine if it is enabled via cookie:

// let the server know JavaScript is enabled via session cookie
document.cookie = "js=1; path=/";

Then detect existence server-side:

HttpCookie cookie = HttpContext.Current.Request.Cookies.Get("js");
bool js = (cookie != null) && (cookie.Value == "1");

Once they close the browser this cookie will go away.

i think this artical will usefull to check the javascript enable or not from server side check if javascript is enabled from server side

发布评论

评论列表(0)

  1. 暂无评论