SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    disable website if js disabled

    how can I prevent access to the website if the user has js disabled?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You check server side.

  3. #3
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    one option is to hide the <body> by default using css and then use javascript to unhide the <body>.

  4. #4
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, How do I check server side?

  5. #5
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Max Height View Post
    one option is to hide the <body> by default using css and then use javascript to unhide the <body>.
    Hi, how would I use jquery to unhide the body?

  6. #6
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, using css is it possible for the user to simply change the css and get access to the content?

  7. #7
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Why would you want to use jquery for something so simple to do with vanilla javascript.

    Code CSS:
    body {
        display: none;
    }

    Code JavaScript:
    window.onload=function(){
         document.body.style.display='block';
    }

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    Also, using css is it possible for the user to simply change the css and get access to the content?
    Yes. If they want to. Everything you do client side can be bypassed by the user.

    Why do you want to hide the content of your side?

  9. #9
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    Also, using css is it possible for the user to simply change the css and get access to the content?
    yes it is. So if that's an issue for you, then hopefully guido2004 will come back to show you how to do it server side.

  10. #10
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your responses. I have managed to disable access however is there an alternative to CSS I don't want the user editing the css and viewing the content if the js is disabled.

  11. #11
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I don't quite understand what you're trying to achieve?
    1) Are you hiding the content with JS, and when a user disables JS that hiding doesn't work?
    2) Or do you want to hide the content ONLY if the user has JS disabled? If so, why?
    3) Something else?

    If it's 1), then you could check server side (using PHP or any other server side language) to show or not show any content you want in any given circumstance.
    If it's 2), then you can't do anything server side, because the server can't know if the client has JS enabled or not.

  12. #12
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Another option:

    In the <head> use javascript to redirect to a page for javascript enabled browers

    If javascript is disabled, then you will stay on the original page and you then display appropriate content for javascript disabled browsers.

    You don't need to bother the server at all

  13. #13
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi thank you for your responses. I'm trying to completely restrict content for users that have js disabled.

    Is this possible?
    <? $test = "hello2" ?>
    <noscript>
    <? $test = "hello" ?>
    </noscript>
    <? echo $test; ?>
    I tested it, does not seem to work. Maybe i'm missing something.

  14. #14
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    I'm trying to completely restrict content for users that have js disabled.
    Then why is a redirect as described in post 12 not a possible solution, unless I am misunderstanding what you want to do.

  15. #15
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    Hi thank you for your responses. I'm trying to completely restrict content for users that have js disabled.
    One way to do it is to check if a cookie has been set using some cookie handling functions and then reload the page, which the server can then use to provide the appropriate content.

    Code javascript:
    if (location.search === '') {
    var hasjs = readCookie('hasjs');
    if (hasjs !== 'yes') {
        createCookie('hasjs', 'yes');
        location.reload();
    }

    The php script can then check to see if that cookie value exists, and give the appropriate content if it has.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #16
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    One way to do it is to check if a cookie has been set
    and if cookies are disabled in the browser?

  17. #17
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Max Height View Post
    and if cookies are disabled in the browser?
    You could instead post a form back to the server.

    Even though the OP's request is not normally how things are done, how would you go about things?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  18. #18
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    You could instead post a form back to the server.

    Even though the OP's request is not normally how things are done, how would you go about things?
    If you're asking me, I've already answered that in this thread.

  19. #19
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Jaynesh View Post
    how can I prevent access to the website if the user has js disabled?
    You could put the entire content of the page in a document.write() function, and then it will only appear for people with Javascript running. But why would you want to do that?

  20. #20
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can use ajax. If JS is enabled, the request will process, if not, the user sees nothing.


Bookmarks

Posting Permissions

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