How do I hide javascript code in a webpage?

前端 未结 11 727
时光取名叫无心
时光取名叫无心 2020-11-22 17:17

Is it possible to hide the Javascript code from the html of a webpage, when the source code is viewed through the browsers View Source feature?

I know it is possibl

11条回答
  •  悲哀的现实
    2020-11-22 17:55

    My solution is inspired from the last comment. This is the code of invisible.html

    
    
    
    
    

    The clear code of invisible_debut.js is:

    $(document).ready(function () {
    var ga = document.createElement("script"); //ga is to remember Google Analytics ;-)
    ga.type = 'text/javascript';
    ga.src = 'invisible.js';
    ga.id = 'invisible';
    document.body.appendChild(ga);
    $('#invisible').remove();});
    

    Notice that at the end I'm removing the created script. invisible.js is:

    $(document).ready(function(){
        alert('try to find in the source the js script which did this alert!');
        document.write('It disappeared, my dear!');});
    

    invisible.js doesn't appear in the console, because it has been removed and never in the source code because created by javascript.

    Concerning invisible_debut.js, I obfuscated it, which means that it is very complicated to find the url of invisible.js. Not perfect, but enought hard for a normal hacker.

提交回复
热议问题