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


how can I prevent access to the website if the user has js disabled?
You check server side.
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
one option is to hide the <body> by default using css and then use javascript to unhide the <body>.


Sorry, How do I check server side?




Also, using css is it possible for the user to simply change the css and get access to the content?
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'; }
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget


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.
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.
Guido - Community Team Advisor
Do you know where the (database) error is? Add it to the list!
Thinking Web: Voices of the Community
Blog - Free Flash Slideshow Widget
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![]()


Hi thank you for your responses. I'm trying to completely restrict content for users that have js disabled.
Is this possible?
I tested it, does not seem to work. Maybe i'm missing something.<? $test = "hello2" ?>
<noscript>
<? $test = "hello" ?>
</noscript>
<? echo $test; ?>


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


Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript


You can use ajax. If JS is enabled, the request will process, if not, the user sees nothing.
Bookmarks