How to redirect if javascript is disabled on asp.net mvc main page

I have a main page where I want to check if the user has disabled his javascript and then redirected to a simple error.aspx page

+3
source share
2 answers

On the main page just add this code

<noscript>
<% Response.Redirect(Url.Action("ActionName","ControllerName")); %>
</noscript>

If the user has disabled javascript, it is redirected to a specific controller action.

+5
source

The usual way to solve this problem is to redirect the user with javascript enabled and display an error for the user who disabled it using the tag noscript.

 <script type="text/javascript">
     location.href = 'pagethatneedsjavascript.aspx';
 </script>
 <noscript>
     This page needs JavaScript enabled!
 </noscript>

, , , ,

<a href="/linktopage.aspx?js=disabled"
onclick="location.href='/linktopage.aspx?js=enabled';return false;">the page</a>

javascript, , href, JavaScript onclick.

, ""

if ( Request.QueryString["js"] == "disabled" ) {
    Response.Redirect("error.aspx");
}

, , js = enabled js.

+4

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


All Articles