asp.net mvc - How to detect whether a browser enables javascript s.t. the master page can make a proper response? -
i developing site using asp.net mvc 3 razor.
in _layout.cshtml
(the master page) want put logic based on whether or not browser enables javascript.
what simplest way make logic?
for sake of simplicity, let master page output follows:
@if(....)//need modify { <p>javascript enabled...</p>} else {<p>javascript disabled...</p>}
there's no way find out on server, therefore there's no way find out before first page loaded. best can put bit of javascript page sets cookie or posts ajax response server telling javascript active, can on subsequent page requests. apart obvious problem of first page load, it's bad strategy since user may switch off javascript in meantime while server still thinks it's active.
graceful degradation/progressive enhancement keywords here. make page assume default no javascript active , act accordingly, i.e. serve plain html in either case. include javascript "upgrade" site's functionality if javascript active. let client figure out if javascript working or not , give means work in either case.
Comments
Post a Comment