4

Let's say that we have a file with .js extension. We all know that it's a javascript file, but let us assume that the file type is not the usual text/javascript, instead it is text/anythingelse. Also, I have a interpreter installed that can interpret the data in the .js file with type text/anythingelse and give me pure javascript as output. But the question is how can I include the .js file with type text/anythingelse in the html markup ? As :

<script type="text/anythingelse" src="myfile.js"></script>

is not seeming to work ! The interpreter is designed something like this :

const Interpret = () => {
 const el = document.querySelectorAll("script[type='text/anythingelse']")
 for ( var i = 0; i < el.length; ++i ) {
   // Interpretaion process start from here......observe the "el" constant
 }
}

So how can I do that ?

6
  • You may have to retrieve it via a network request instead Commented Jan 26, 2020 at 13:24
  • @CertainPerformance Should I use AJAX ? Commented Jan 26, 2020 at 13:28
  • You definitely can, but I'm not 100% certain it's the only solution Commented Jan 26, 2020 at 13:28
  • @CertainPerformance Ok then, if it's not the only solution, please let me know about the more solutions. Please add an answer. Commented Jan 26, 2020 at 13:31
  • 1
    I don't know, else I would've said Commented Jan 26, 2020 at 13:32

1 Answer 1

1

you can download the file using XMLHttpRequest()

var xhr = new XMLHttpRequest();
    xhr.open("GET", f_strUrl);
    //xhr.setRequestHeader('origin',undefined);
    xhr.responseType = "blob";//use what matches your case
    xhr.onload = function(){
        var reader  = new FileReader();
        reader.onload = function(event) {
            var l_data = event.target.result;
            //process your data

            if(f_funcCallback != null){
                f_funcCallback(f_strUrl,imgData);
            }
        }.bind(this);
        reader.readAsDataURL( xhr.response);    
    };

you can check the details here https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.