Javascript how to create a script tag dynamically without a source file?

My debug.html page got this:

window.onload = function() {
    var dataFromLink = parseData(location.search.substring(5));
    callScript(dataFromLink);
};

</script>

And my debugBoot.js got the following:

function parseData(dataFromLink){
    dataFromLink=dataFromLink.replace(/%20/g, ' ');
    dataFromLink=dataFromLink.replace(/%22/g, '"');
    dataFromLink=dataFromLink.replace(/%27/g, '\'');
    dataFromLink=dataFromLink.replace(/%3C/g, '<');
    dataFromLink=dataFromLink.replace(/%3E/g, '>');
    return dataFromLink;
}

function callScript(param1) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.innerHTML = param1;
    script.id = "debugScript";
    script.src = "debugScript.js";
    document.getElementsByTagName("head")[0].appendChild(script);
    return false;
}

And my data from location.search.substring (5) looks like this when I load the page, but with the employees that I release in the parseData function:

function execute(doSave) { 
    dss.login(userId);
    return true;
}

So, I have a web application where I got the WEBContent folder, and there is my debugScript.js file

My code reads the file from there with the following line:

script.src = "debugScript.js";

and it works, but I have a problem ...

, , , , FromLink , . , . , , eclpise, script , , .

,

Not allowed to load local resource: file://...

, - script - , script , dataFromLink ...

?

, , -, , ?

:)

+4
1

:)

, , , , .

, 1, textarea, javascript, , :

<script id=loadScript>
    window.onload = function() {    
        callScript(fileName, userId);   
    };
</script>


function callScript(fileName, userId) {
    var script = document.createElement("script");
    script.type = "text/plain";
    script.id = "debugScript";
    script.src = ".../getSource/" + userId + "/" + fileName;
    document.getElementsByTagName("head")[0].appendChild(script);
}
+2

Source: https://habr.com/ru/post/1665972/


All Articles