It's possible to disable an entire page html if the js is disabled on the browser of the user?
EDIT:
Thank you all for the answers and comments! However, what I mean is: I want that the page is replaced with something else, like an image, in that case.
Asked
Active
Viewed 2,940 times
2

CCT
- 61
- 1
- 8
-
not exactly a duplicate, but this thread will answer your question: http://stackoverflow.com/questions/6724515/what-is-the-purpose-of-the-html-no-js-class – durbnpoisn May 23 '16 at 18:49
-
Do you mean disable a link to page? Or what do you mean exactly by "disable"? – Steven B. May 23 '16 at 18:50
-
You'll probably need the page to render the replaced content by default with a JS call that actually swaps that out for the real content. If JS is disabled, the call won't go through and the failover content is shown, but if the JS call is successful then it would show the proper content – theaccordance May 23 '16 at 19:00
-
I edited the question. Sorry if I wasn't clear enough. – CCT May 23 '16 at 19:00
-
@Yosvel's answer is what you want. – Seth May 23 '16 at 19:17
2 Answers
7
The noscript
tag defines an alternate content for users that have disabled scripts in their browser or have a browser that doesn't support script.
You can do something like this in your html body to display whatever image you want to show:
<noscript>
<style type="text/css">
.wrapper {display:none;}
</style>
<div>
<img src="src/to/your/image.png" alt="You don't have javascript enabled">
</div>
</noscript>
The css inside the noscript
tag will hide the html content inside the wrapper
class.

Yosvel Quintero
- 18,669
- 5
- 37
- 46
0
Not that I am aware of. Somewhere somehow you need to tell the browser to prevent the action/event linked to it, eg returning false, which is a task for javascript. I can come up with two alternatives:
Make all anchors dummies and correct them when JS is turned on:
<a href="#" data-href="/actual-url">foo</a>
$('a').each(function(){ this.href = $(this).data("href");} // * jQuery for simplicity
Put an layer on top of the anchor, which you can remove with JS.
.BlockedAnchor a{ position: relative; }
.BlockedAnchor a:before{
position: absolute;
display: block;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
$('body'removeClass("BlockedAnchor");

Martijn
- 15,791
- 4
- 36
- 68