Check if Javascript is disabled

Last post 10-01-2007 4:19 AM by mahag. 11 replies.

Sort Posts:

  • Check if Javascript is disabled

    09-29-2007, 12:39 PM
    • Loading...
    • JRICE
    • Joined on 05-11-2006, 12:52 AM
    • Lebanon-Beirut
    • Posts 667

    I want to redirect mu users to a Specifc Page, If javascript was disabled??

    Im using Asp.net 2.0, Ajax Enabled, Internet explorer
    ------------------------------------------------------
    I tried

    if (!Request.Browser.JavaScript)
    {
      Response.Redirect("JavascriptPage.aspx");
    }

    Request.Browser.JavaScript is obselete
    ------------------------------------------------------
    I also tried

    adding to my master page

    <noscript>
    <META HTTP-EQUIV=Refresh CONTENT="1;URL=http://localhost:1550/Testing/Default.aspx">
    </noscript>

    I failed when i set Allow MetaData Refresh to Disabled in my browser?
    -------------------------------------------------------

     

    Any Ideas?????????????????????????

    Please remember to "Mark As Answer" if this post answered your question!

    Bilal Shouman - MCAD.NET

    |My Blog|
    ---------------------------------


  • Re: Check if Javascript is disabled

    09-29-2007, 4:19 PM
    • Loading...
    • HosamKamel
    • Joined on 01-19-2006, 6:49 PM
    • Egypt
    • Posts 940
    Hosam Kamel



    Remember to click on Mark as answer on the post that helped you
  • Re: Check if Javascript is disabled

    09-29-2007, 6:38 PM
    • Loading...
    • JRICE
    • Joined on 05-11-2006, 12:52 AM
    • Lebanon-Beirut
    • Posts 667

    Thank you for ur reply

    but this link didnt solve my problem since i tried both solution mentioned in the given link

     

    Any ideas?

    Please remember to "Mark As Answer" if this post answered your question!

    Bilal Shouman - MCAD.NET

    |My Blog|
    ---------------------------------


  • Re: Check if Javascript is disabled

    09-30-2007, 3:15 AM
    • Loading...
    • nps
    • Joined on 09-21-2007, 11:50 AM
    • Coimbatore
    • Posts 386

    Hi ,

    Try this 

    if (Request.Browser.JavaScript)

    {

    Response.Write("Javascript Enabled") ;

    }

    else

    {

    Response.Write("Javascript Disabled") ;

    N.P.Senthil
    Software Engineer
  • Re: Check if Javascript is disabled

    09-30-2007, 8:46 AM
    • Loading...
    • azamsharp
    • Joined on 06-11-2003, 9:36 AM
    • Houston,Texas
    • Posts 4,248

     Request.Browser.JavaScript only indicates whether the browser handles the JavaScript or not. You can turn off the JavaScript and it will still say "true". Here is a simple way to test if the JavaScript is enabled or not.

    You print a message on the page saying "If you see the message below then the JavaScript is enabled". This means if the message is not displayed then the JavaScript is disabled.

     <body onload="checkJavaScriptValidity()">


    <script language="javascript" type="text/javascript">

    function checkJavaScriptValidity()
    {
        document.getElementById("divDisplay").innerHTML = "If you see this message then your JavaScript is enabled.";
    }

    </script>

     

     

     

    Hope it helps!
    AzamSharp
    Blog AzamSharp
    RefactorCode
    GridViewGuy
  • Re: Check if Javascript is disabled

    09-30-2007, 11:06 AM
    • Loading...
    • bpw
    • Joined on 09-25-2004, 5:57 AM
    • Warrington, England
    • Posts 349

    Although I’ve never done this, I will have to in the near future so I’ve been watching the thread.

    It seems to me that a good way to do this is to break the page into two panels <divs>, the first visible (‘display: block’ – the default) with a message saying ‘Javascript is disabled, please enable it’, and the second invisible (display: none;). On page load a Javascript function will hide the first panel and show the second.

    document.getElementById("JsWarning").style.display = "none";
    document.getElementById("theContent").style.display = "block";

    If there’s no Javascript, the first panel will show. It will not redirect them of course, but the required content can be shown in the first <div> (one less trip to the server).

    Will this work, or am I missing something?

    Paul Weston
  • Re: Check if Javascript is disabled

    09-30-2007, 11:50 AM
    • Loading...
    • bpw
    • Joined on 09-25-2004, 5:57 AM
    • Warrington, England
    • Posts 349

    Mmm, I guess the Javascript-enabled browser would initially see the warning message?

    I wonder why the <noscript> option doesn’t work? This seems to be the most popular option.

    <noscript>
     <meta http-equiv=”Refresh” content =”0;URL=noscript.aspx” />
    </noscript>

    I get a warning that it shouldn’t appear in the <head> section, but apparently this is an oversight and can safely be ignored?

    Paul Weston
  • Re: Check if Javascript is disabled

    09-30-2007, 5:55 PM
    • Loading...
    • azamsharp
    • Joined on 06-11-2003, 9:36 AM
    • Houston,Texas
    • Posts 4,248

     You can do something like this:

    <div id="jsEnabled" style="visibility:hidden">
        JavaScript is enabled
        </div>
       
        <div id="jsDisabled">
        JavaScript is disabled
        </div>

     <script language="javascript" type="text/javascript">

    function checkJavaScriptValidity()
    {
        document.getElementById("jsEnabled").style.visibility = 'visible';
        document.getElementById("jsDisabled").style.visibility = 'hidden';
    }

    </script>

    ;) 

     

    Hope it helps!
    AzamSharp
    Blog AzamSharp
    RefactorCode
    GridViewGuy
  • Re: Check if Javascript is disabled

    09-30-2007, 6:29 PM
    • Loading...
    • JRICE
    • Joined on 05-11-2006, 12:52 AM
    • Lebanon-Beirut
    • Posts 667

    I want to redirect user to another page in case of javascript disabled

    Please remember to "Mark As Answer" if this post answered your question!

    Bilal Shouman - MCAD.NET

    |My Blog|
    ---------------------------------


  • Re: Check if Javascript is disabled

    10-01-2007, 1:23 AM
    • Loading...
    • HosamKamel
    • Joined on 01-19-2006, 6:49 PM
    • Egypt
    • Posts 940
    Hosam Kamel



    Remember to click on Mark as answer on the post that helped you
  • Re: Check if Javascript is disabled

    10-01-2007, 1:33 AM
    • Loading...
    • JRICE
    • Joined on 05-11-2006, 12:52 AM
    • Lebanon-Beirut
    • Posts 667

    I want to redirect mu users to a Specifc Page, If javascript was disabled??

    Im using Asp.net 2.0, Ajax Enabled, Internet explorer
    ------------------------------------------------------
    I tried

    if (!Request.Browser.JavaScript)
    {
      Response.Redirect("JavascriptPage.aspx");
    }

    Request.Browser.JavaScript is obselete
    ------------------------------------------------------
    I also tried

    adding to my master page

    <noscript>
    <META HTTP-EQUIV=Refresh CONTENT="1;URL=http://localhost:1550/Testing/Default.aspx">
    </noscript>

    I failed when i set Allow MetaData Refresh to Disabled in my browser?
    -------------------------------------------------------

     

    Any Ideas?????????????????????????

    Please remember to "Mark As Answer" if this post answered your question!

    Bilal Shouman - MCAD.NET

    |My Blog|
    ---------------------------------


  • Re: Check if Javascript is disabled

    10-01-2007, 4:19 AM
    • Loading...
    • mahag
    • Joined on 02-16-2007, 2:35 AM
    • Lebanon - Beirut
    • Posts 67

    You can do the following:

    Add a hidden textbox in your master page or your page as follows:

    <input type="hidden" id="testBox" runat="server" value="no"/>

    and call the function onload, if javascript is working the value in the texbox should change.

    <body onload="CheckJsc()"> in your master page

    <script type="text/javascript">

    function CheckJsc() {

    document.getElementById("_ctl0_ContentPlaceHolder1_testBox").value = "yes";

    }

    </script>

    then in the pages were u need to check if javascript is enabled (and these pages are using the master page where u have the hidden textbox)..

    Check if the value in the textbox has changed if not redirect to the javascript.aspx page:

    dim s as string  = testbox.text or master.findcontrol("textBox").text

    if (s="no")

    ' javascript is not working so

    ' response.redirect("...")

    else

    'continue ...

     

    Dont forget to Mark as Answer if my reply helped you....
Page 1 of 1 (12 items)