Javascript testing is included in ASP.NET MVC

I was looking for a way to check if a user supports Javascript or a browser that supports it in ASP.NET MVC, and if they do not send them to a page that tells them the site requires it to work.

However, I could not find a definitive answer to this ... any suggestions?

+4
source share
5 answers

You can use the <noscript> element. http://www.w3schools.com/TAGS/tag_noscript.asp . This would not redirect them to another page, but you could put a link that they can click to go to another page.

+3
source

I was looking for the best ways to do this tonight and came across, I think, a brilliant solution.

 <noscript> <meta http-equiv="refresh" content="0;URL=http://yoursite.com/noJavascript" /> </noscript> 

This redirects to another page if javascript is disabled without the need to call functions, hide / show divs and worry about the DOM update flash.

I know this has already been answered, but I have not seen such an approach anywhere on SO. If there is a reason, someone informed me :)

+6
source
 function isJavaScriptEnabled() { return true; } 

I'm actually half serious about this. You can use this to check if JS is turned on and cache the result in the session.

the <noscript> parameter seems most appropriate.

what you have to do is make your site fully accessible without javascript enabled, and then gradually improve the site using javascript.

+1
source

You can use the html tag to display a message in the browser when JavaScript is disabled.

 <noscript>Your browser has disabled JavaScript.</noscript> 
+1
source

You can check the capabilities of the browser, which is part of HttpRequestBase, which is part of httpcontextbase; however, this is not final and the best way to ensure that your application works when JavaScript is not designed to customize your application using an unobtrusive approach to using JavaScript.

This ensures that your application works as if it were on any server application, then you use JavaScript to intercept links, click buttons, etc. to enable client-side AJAX functions.

0
source

Source: https://habr.com/ru/post/1303158/


All Articles