Hide HTML code

3

This is where you can, if you can, access any website that disables javascript and do F5 to update. You will see that the content of the site has disappeared, however if you load for example CTRL + U , you will see that HTML is still there.

What I like to know is how do I hide some HTML when javascript is disabled:)

I know there is something like this but with the adblock script, it hides HTML as long as we have adblock enabled.

But I wanted but it's something similar or equal, but only with the javascript turned off:)

    
asked by anonymous 09.04.2015 / 18:47

4 answers

2
  • Use <iframe/> . The browser needs the generated HTML to display your site.

  • You can not hide the HTML code completely.

  • Do not prompt the user to find more ways to find your code.

  • Any solution on the client side is a waste of time (and if the user disables JS?).

  • What do you need this for?

  • 02.12.2015 / 08:18
    1

    You can load the page with display: none and when the page loads, a javascript script removes this display none, so if you do not load js, the code will not be displayed.

        
    09.04.2015 / 19:23
    1

    You can load page content dynamically with AJAX, using jQuery for example. This way, if JavaScript is disabled in the browser, the content will not be loaded.

    jQuery has a method called .load () that allows you to load the response body in the element.

    I made a fiddle to exemplify: link

    $("#content").load("/echo/html/", {"html": "<h1>Teste</h1><p>Texto Teste</p>"});
    

    The load method receives a URL as its parameter. In that case I used the JsFiddle service to create an ajax request.

    More generally:

    $(elemento).load(url);
    
        
    16.08.2015 / 21:26
    0

    It is not possible to hide the user's source code once the browser has already loaded it. The maximum that can be done is a condition by PHP, so the code is not shown, but since PHP is a server-side language, it can not detect JavaScript in the browser.

    And another, the <noscript> element is for displaying content when JavaScript is disabled, but if we access the source code, all HTML is still there. Generally what happens on this site is that the elements are only shown with JavaScript, see what you have in the body tag of the site:

    <body id="bg" onload="inicializar()">
    

    In other words, when the site loads, the inicializar() function will show the site content, however, all HTML is still there, only hidden visually.

    I would like to warn you that this practice should be avoided, after all, not all users enable JavaScript, making the experience of accessing your site a total disaster. Please read: Support for non-Javascript users is running out?

        
    09.04.2015 / 20:03