Is it possible to load in a local version of a JavaScript file instead of the server version?

前端 未结 5 863
醉梦人生
醉梦人生 2021-02-08 04:59

Just had a quick question to throw out and see if there was a solution for this...

Let\'s pretend I have no access to the server. I load up a webpage and find out that t

5条回答
  •  不思量自难忘°
    2021-02-08 05:27

    In a browser that supports FileReader such as Chrome, yes, in combination with 'eval' to execute arbitrary JS. In your HTML add a button for the user to press:

    In your scripts add:

    function load() {
      var reader = new FileReader();
      reader.onload = function(evt) {
        eval(evt.target.result);
      };
      reader.readAsText(files[0]);
    }
    

提交回复
热议问题