www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: detect javascript enabled or disabled

  1. #1
    Join Date
    Jan 2008
    Posts
    15

    detect javascript enabled or disabled

    Hi

    I would like to know how can i detect Javascript enabled or disabled, and if disabled then i would like redirect user to different version of the website.

    I know how to detect javascript enabled or disabled but unable to find a way our redirect website.

    Kind Regards
    Bhavesh

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774
    There was a similar thread to this months ago, and nobody could come up with a real solution. The problem stems from the META refresh HTML tag. Initially a META refresh could be used, but once that's set in motion, JavaScript cannot intercept and stop it. You can however do something like this:
    Code:
    function hideScriptDisabled() {
      document.getElementById("scriptDisabled").display = "none";
    }
    Then in your HTML body:
    HTML Code:
    <p id="scriptDisabled">You have JavaScript disabled, <a href="#">click here</a>.</p>
    <script type="text/javascript">hideScriptDisabled();</script>

  3. #3
    Join Date
    Feb 2006
    Posts
    2,927
    Redirecting is always a poor use of the server and client's time.

    Write webpages that are worth looking at without javascript, and add script to those clients that support it.

    Google 'unobtrusive javascript' for some examples.

  4. #4
    Join Date
    Aug 2007
    Posts
    3,767
    You can do it if you redirect if Javascript is enabled, as opposed to disabled.

  5. #5
    Join Date
    Jan 2008
    Posts
    15
    Thanks

    I'm designing web application so javascript is required. So if the browser's javascript is disabled then webpage should not allow it to continue further.

    Kind Regards
    Bhavesh

  6. #6
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774

  7. #7
    Join Date
    Jan 2008
    Posts
    15
    Thanks for your response.

    I managed to resolve the problem.

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by toicontien
    There was a similar thread to this months ago, and nobody could come up with a real solution. The problem stems from the META refresh HTML tag. Initially a META refresh could be used, but once that's set in motion, JavaScript cannot intercept and stop it.
    Really? I though it is as simple as that:
    Code:
    <noscript>
    <meta http-equiv="refresh" content="0;url=http://www.mysite.com/nojavascriptpage.html" />
    </noscript>

  9. #9
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774
    Quote Originally Posted by Kor
    Really? I though it is as simple as that:
    Code:
    <noscript>
    <meta http-equiv="refresh" content="0;url=http://www.mysite.com/nojavascriptpage.html" />
    </noscript>
    Works for me. It's been a while since I saw the thread, and if I remember correctly it got a ton of replies.

  10. #10
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Except for the fact that <noscript> is invalid in the <head> and <meta> is invalid in the body that code would be the ideal solution. Unfortunately the only places where using <noscript> are actually still useful are invalid according to the standards and therefore browsers are not required to support it.

    It would actually make much more sense today if <noscript> were only valid in the head of the page instead of only valid in the body since it is only in the head of the page that it is actually needed. All use of noscript in the body (the only place where it is valid) is now better handled using JavaScript to hide the elements instead.

  11. #11
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    In theory probably <noscript></noscript> should not be valid in HEAD (though I don't see a decent reason for it should not be), yet in practice it is. You may test this in the modern browsers (IE and Moz certainly pass this test)

  12. #12
    Join Date
    Oct 2009
    Posts
    1
    1. Create a new page for noscript, e.g. page2.htm
    2. Add the following lines at the top of your existing page:
    <noscript>
    <head><meta HTTP-EQUIV="REFRESH" content="0;url=page2.htm"></head>
    </noscript>

    3. That's IT!

  13. #13
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by jerryxiao View Post
    1. Create a new page for noscript, e.g. page2.htm
    2. Add the following lines at the top of your existing page:
    <noscript>
    <head><meta HTTP-EQUIV="REFRESH" content="0;url=page2.htm"></head>
    </noscript>

    3. That's IT!
    Nope. If javascript is enabled, the document will have no HEAD, which is HTML illegal. If you write another HEAD outside the NOSCRIPT tag, the document will have two HEADs in case javascript is disabled, which is HTML illegal as well.

  14. #14
    Join Date
    Jan 2010
    Posts
    3

    Isn't simple as this:?

    Create a default.asp (in my case I'm using Classic ASP) and insert only this lines:

    <script type="text/javascript" language="javascript1.5" >
    location.href='/home.asp';
    </script>
    <meta http-equiv="Refresh" content="1;URL=/home.asp">

  15. #15
    Join Date
    Jan 2010
    Posts
    3
    Ooops.. the second url obviously would be something like: /noJavascript.asp

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles