Forget the pessimist or cautions who say it is not possible, it is perfectly possible and feasible!
I do so, I believe it is the most practical and semantic way, just you put this in your <head>
, thus:
<noscript><style>.notjs{display:none:!important;}</style></noscript>
In the element you want to hide, include the class notjs
, thus:
<input type="text" name="search" class="notjs">
If you are using Select2, jquery or something that breaks your design as is my case, use bootstrap, put the css version below the javascript version, this way:
<input type="text" name="search" class="notjs">
<noscript><input type="text" name="search" class="form-control"></noscript>
It will replace the input automatically, hiding one and showing the other, when javascript is enabled you can use jquery or another js library to remove the css version that will work without JS, you will find in google how to delete elements manipulating the DOM, this is quiet. Always remember that this code has no effect on the view-source, because there it does not load any code, it is just a text, more will have effect on your live page and you will not see the code in the DOM(console) and is sufficient for this type of situation.
Now, if you still believe that the user should not see that page without javascript, then we have 2 options;
!) we take the user out of the problematic page and take him to one that works only with basic (html and css).
- we cover the page with a black background and put a warning to inform that javascript is required.
- In the first case we can do so:
If javascript is disabled it will redirect the user immediately to another page, surely he will be very nervous not to do what he intended, usually use the locked button of the mouse or copy something and hardly he will be able to, especially if you put this code just below the <head>
. The browser will understand the message and will do what you ask, at most the person will be trying to prevent the full upload, the same technique used to access the sheet, State, the globe and others, more as the tag is at the top, will not work, are thousandths of seconds, when you think of clicking on X, it’s gone.
<!doctype html>
<html lang="en">
<head>
<noscript><meta http-equiv="refresh" content="0; URL='/minha-outra-pagina'"/></noscript>
- In the second case I will not show the code, my answer turned into a tutorial, but I will give you the theoretical, you will use the same initial code, more with some differentials, the first of them is that you do not hide or touch anything, you will just change the color of the
<body>
, include this before </head>
, thus: <noscript><style>.cnotjs{background-color:black:!important;}</style></noscript>
. In the <body>
let’s include the class cnotjs
, thus: <body class="cnotjs">
, Should be enough for no one to see anything, unless you put a blue or white text there, then the procedure is another.
Finally, you will create an Alert within the tag <noscript><!--- Aqui dentro ---></noscript>
, can be with a div, you should apply a Z-INDEX on Alert to ensure that it will override the other elements and that’s it, now you can sleep quietly without worrying about those things.
I think if you hid your body by default with
CSS
usingbody { display: none; }
and used the JS to display would work.– Richard Dias
You can use the tag
<noscript>
to display content when no javascript is enabled.– Franchesco
You want to hide the rendered page or the source code?
– Guilherme Nascimento
Richard Dias, maybe it works :) then expression :P Guilherme Nascimento, I want to hide the source code.
– BabyStar
@Babystar then none of the examples cited will work, in fact it is not possible to hide the code, what is possible to do is to make it difficult to read it and even with Javascript enabled and you locked the contextmenu and Ctrl+U still is easy to see the source code.
– Guilherme Nascimento
I think I’ll do as I have for example the status board as it is up there in the upper right :) If I disable javascript you only see the board loading, and even if you go to the source code, you will not see the content code, only see the <img> tag of the loading :P This should be the best way xD
– BabyStar
you must apply the tag
<noscript>
to check that a particular code snippet does not appear when javascript is disabled. The problem lies in the way you asked the question, as well as the title that they imply you want to hide the code.. What you seem to want is to prevent the rendering or execution of specific snippets of code.– Daniel Omine