4

My debug.html page got this:

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

</script>

And my debugBoot.js got this:

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 the location.search.substring(5) looks like this when I load the page but with staff I get rid of in parseData function:

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

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

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

script.src = "debugScript.js";

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

The link, that I use to come to the page where I have this code, triggers also a function that saves the dataFromLink to the file, from where I call the data. That works just fine, but there is a problem. Always when the function saves the data, I need to refresh the eclpise file so that my script can read it, if I don't refresh the file, its just its old version.

I tried to save it to local disk, but then I get an error from the browser

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

Long story short, I need somehow to create a script without to read any file, but to insert an empty script into the page, and then to write the stuff from dataFromLink to it...

Is it possible?

or maybe to create a temporary file somewhere, but not on the server from witch I can read?

I would accept any solution :)

2
  • It’s a bit hard for me to understand your problem or your goal… do you want to create a temporary JavaScript file and execute it? Do you want to save a JavaScript file and load it in Eclipse? Dynamically generate a JavaScript file? I’m not sure what exactly you want. In any case, you can create temporary files with the Blob API. Commented Jan 20, 2017 at 3:06
  • i have two pages, in the one i have a textarea, there i write a javascript code, once done, i go to the second page to debug it, on clienside, to do so, i need to import the text from the textarea as a script into my page, therefore, i need to create a script 1st, but without the src file, but with the text i sent to it...i hope i got u an idea... Commented Feb 2, 2017 at 8:57

1 Answer 1

1

Forgot to answer :)

Ok, the problem I had there, could not be solved the way I wanted.

What I did in the end was, that I used the source from the page one, where the textarea was, and created a javascript file, whose name I sent as a parameter to the second page, witch then could find the file in the file system and open it like this:

<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);
}
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.