Substituir type file por variável com url definido
Olá,
HTML:
<a onclick="call_menu(FILE, 'file_open');" href="#">Escolher arquivo...</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();
};No html ao clicar em escolher arquivo executa o trecho acima do javascript.
Mas agora preciso que seja diferente, tirar a opção escolher arquivo que é o que o código acima faz e ao invés disso ter uma variável que recebera um arquivo (url) definido/fixo.
Acontece que ´this.open_handler´ é a função abaixo:
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);
}};
Meu objetivo é apenas eliminar no front end o botão acima para escolher arquivo. e criar uma varivel com valor fixo (contendo a url do arquivo)
Sou iniciante com javascript
Agradeço ajuda
Discussão (4)
Carregando comentários...