jeudi 16 avril 2015

Pass toDataUrl to image input of other function

I have some troubles passing dataurl value to another function in Javascript. By clicking on a link



<a id="imageSaver" href="#">Save image</a>


the canvas is converted toDataUrl



var imageSaver = document.getElementById('imageSaver');
imageSaver.addEventListener('click', saveImage, false);

function saveImage(e) {
this.href = canvas.toDataURL("image/jpg", 1.0);
this.download = 'test.jpg'
}


In my other function I have an upload button, that I want to replace with the image data that is created with click on "imageSaver". See the upload function of the second part:



<input type="file" id="imageInput" accept="image/*" value="Bild hochladen">
<a href="#" id="imageSelect">Foto hochladen</a> <br>
window.onload = function(){
var imageSelect = document.getElementById("imageSelect"),
imageInput = document.getElementById("imageInput");
imageSelect.addEventListener("click", function (e) {
imageInput.click();
e.preventDefault();
}, false);

imageInput.addEventListener("change", function (e) {
handleFiles(this.files);
}, false);


Has anyone an Idea how to pass the data to the other function instead of the upload function?


Aucun commentaire:

Enregistrer un commentaire