HTML:
<a onclick="call_menu(FILE, 'file_open');" href="#">Choose file...</a>
Javascript:
//open
this.file_open = function () {
this.open();
};
this.open = function () {
document.getElementById("tmp").innerHTML = '';
var a = document.createElement('input');
a.setAttribute("id", "file_open");
a.type = 'file';
a.multiple = 'multiple ';
document.getElementById("tmp").appendChild(a);
document.getElementById('file_open').addEventListener('change', this.open_handler, false);
//force click
document.querySelector('#file_open').click();
};
In html to click “Choose file” runs the excerpt above javascript.
But now I need to be different, I must eliminate the option to choose file and put a variable that will receive a file (url) set / fixed.
“this.open_handler” is the function below:
this.open_handler = function (e) {
var files = e.target.files;
for (var i = 0, f; i < files.length; i++) {
f = files[i];
if (!f.type.match('image.*') && f.type != 'text/xml')
continue;
if (files.length == 1)
this.SAVE_NAME = f.name.split('.')[f.name.split('.').length - 2];
var FR = new FileReader();
FR.file = e.target.files[i];
FR.onload = function (event) {
if (this.file.type != 'text/xml') {
//image
LAYER.layer_add(this.file.name, event.target.result, this.file.type);
EXIF.getData(this.file, this.save_EXIF);
}
else {
//xml
var responce = FILE.load_xml(event.target.result);
if (responce === true)
return false;
}
};
if (f.type == "text/plain")
FR.readAsText(f);
else if (f.type == "text/xml")
FR.readAsText(f);
else
FR.readAsDataURL(f);
}};
My goal is just to remove the front end button “choose file” and create a variable with a fixed value (containing the url of the file)
I thought the following:
I exclude the two functions: “this.open” and “this.file_open”, then in the “this.open_handler” function, delete the loop for, but I do not know how to properly take the loop and insert the variable with the url fixed:
var urlmyFixedImage = "image.png";
I am a newbie with javascript