Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts

    A script to check if javascript enabled with a disabling DIV

    Hi all,

    I am writing an administration panel for a web site. I want to check if the client's browser javascript enabled and if it is not enabled, a warning DIV comes telling the client to enable javascript and disable the actual page (make the actual page non-usable). Is there a way to do that?

    Thanks in advance
    telmessos

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    There's a <noscript> tag in html.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts
    is it possible to view the "No javascript warning DIV window" which disables the content of the page with <noscript> tag ???

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Code:
    <p align="center"><font color="#CC0033" size="3" face="Arial"><b>Sorry! &nbsp It appears that your browser does not support JavaScript,<br> or JavaScript has been disabled, possibly by your network administrator.
    Obviously any features of the page which require JavaScript will be unusable if Javascript is disabled. And you cannot use disabled Javascript to reveal or hide some div or message.
    Last edited by Philip M; 12-28-2010 at 03:41 PM.

  • #5
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts
    thanks PhilipM,

    I found noscript already before opening a thread in this forum. When I use noscript tags, the message appears on the top the page but also the content of the page (menus, body, header etc) appears. I do not want the page visitors reach or edit that content without javascript enabled. Otherwise they will be able to click on the menu which is made with javascript functions or submit forms which is normally validated with javascript. As you may understand this is not an ideal situation.

    I hope there's an alternative way for it.

    Thanks again
    telmessos

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I do not want the page visitors reach or edit that content without javascript enabled.
    The only way is to dynamically create all other HTML using javascript.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Or to redirect users who have Javascript enabled to a different page.

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I do not want the page visitors reach or edit that content without javascript enabled. Otherwise they will be able to click on the menu which is made with javascript functions or submit forms which is normally validated with javascript.
    FYI: You've to adopt a progressive enhancement strategy while developing a web page which means your page can serve the basic content and functionality for everyone.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by telmessos View Post
    thanks PhilipM,

    I found noscript already before opening a thread in this forum. When I use noscript tags, the message appears on the top the page but also the content of the page (menus, body, header etc) appears. I do not want the page visitors reach or edit that content without javascript enabled. Otherwise they will be able to click on the menu which is made with javascript functions or submit forms which is normally validated with javascript. As you may understand this is not an ideal situation.

    I hope there's an alternative way for it.

    Thanks again
    telmessos
    this a design problem and an abuse of javascript. If you need javascript to control access to some elements in the page or you validate forms only with javascript you are in trouble because this a server side scripting job. The solution is to redesign the page.

    http://onlinetools.org/articles/unob...ipt/index.html

    PS: AFAIK noscript element doesn't exists in html5, just in case you intend to use it.

    best regards and happy holidays

  • #10
    Regular Coder
    Join Date
    Apr 2006
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks to all answering people.

    First of all, of course I am not planning to make the validation of the information only by Javascript. I will also validate the information using PHP. My concern is, instead of server side validations, using Javascript event driven validations (like on click of a button etc) as they look more user friendly.

    Redirecting the visitor to a second page for validation is not a good option for me. I would like to check if the page is functioning which Javascript or no content to be displayed if the Javascript disabled. All pages contains Javascripts. So once the visitor comes to my page he/she must know that page needs Javascript and can't do anything without it. So it saves the time of everybody. That is my main problem.

    A friend of mine suggested a solution which seems fine for my problem. I wanted to share it with everybody. It is an idea of creating a wrapper division with display:none style setting and make the display option block with Javascript. So if the browser has no Javascript support, only the no script section out of the wrapper division will be shown and the other content will not be displayed.

    That seems ok to me. But if you have any other ideas, I would be happy to hear it.

    Thanks again
    telmessos

  • #11
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    add a class to <body>, "noscript"

    then add a script block at the end of your body tag:
    Code:
    <script> document.body.className=  document.body.className.replace("noscript", "");</script>
    now, you can easily style the whole document in css by appending ".noscript " to any selector to make it toggle only in the non-javascript view.


    ex:
    Code:
     .noscript  form { display: none; }
     .noscript  #disabledScriptWarning { display: block; }
    it's easier to reuse and maintain this code than hard coding specific IDs in javascript; the only thing to adjust is css, and you can do several things at once with a list of selectors...
    Last edited by rnd me; 12-29-2010 at 11:42 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #12
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by rnd me View Post
    add a class to <body>, "noscript"

    then add a script block at the end of your body tag:
    Code:
    <script> document.body.className=  document.body.className.replace("noscript", "");</script>
    now, you can easily style the whole document in css by appending ".noscript " to any selector to make it toggle only in the non-javascript view.


    ex:
    Code:
     .noscript  form { display: none; }
     .noscript  #disabledScriptWarning { display: block; }
    it's easier to reuse and maintain this code than hard coding specific IDs in javascript; the only thing to adjust is css, and you can do several things at once with a list of selectors...
    what you do if a user disable your css or use a browser like lynx,

    best regards

  • #13
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by oesxyl View Post
    what you do if a user disable your css or use a browser like lynx,

    best regards
    nothing; don't cater to horses on highways...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #14
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by rnd me View Post
    nothing; don't cater to horses on highways...
    best. post. ever.


  •  

    Posting Permissions

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