How do I hide javascript code in a webpage?

前端 未结 11 817
时光取名叫无心
时光取名叫无心 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:49

    Approach i used some years ago -

    We need a jsp file , a servlet java file and a filter java file.

    Give access of jsp file to user. User type url of jsp file .

    Case 1 -

    • Jsp file will redirect user to Servlet .
    • Servlet will execute core script part embedded within xxxxx.js file and
    • Using Printwriter , it will render the response to user .

    • Meanwhile, Servlet will create a key file .

    • When servlet try to execute the xxxx.js file within it , Filter
      will activate and will detect key file exist and hence delete key
      file .

    Thus one cycle is over.

    In short ,key file will created by server and will be immediatly deleted by filter .

    This will happen upon every hit .

    Case 2 -

    • If user try to obtain the page source and directly click on xxxxxxx.js file , Filter will detect that key file does not exist .
    • It means the request has not come from any servlet. Hence , It will block the request chain .

    Instead of File creation , one may use setting value in session variable .

提交回复
热议问题