Ich habe eine HTML-Leinwand, die eine Vorschau eines Bildes zeigt, wenn das Bild in einer Eingabe ausgewählt ist. Dies funktioniert in Chrome, aber ich kann es anscheinend nicht in Safari verwenden. Speziell - in Safari - scheint die onchange="previewFile()"
die Funktion previewFile nicht aufzurufen.Eingabe onchange Javascript Funktionsaufruf funktioniert nicht in Safari
<canvas id="canvas" width="0" height="0"></canvas>
<h2>Upload a photo </h2>
<input type="file" onchange="previewFile()"><br>
<script type="text/javascript">
// setup the canvas
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
// grab the photo and display in canvas
var photo = new Image();
function previewFile() {
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
reader.addEventListener("load", function() {
photo.src = reader.result;
canvas.height = photo.height;
canvas.width = photo.width;
ctx.drawImage(photo,0,0);
}, false);
if (file) {
reader.readAsDataURL(file);
}
}
</script>
Vielen Dank! Das hat das Problem gelöst und du hast mir das eine oder andere beigebracht! – rcrusoe