Reputation: 13543
I'm currently trying to make an image preview on the client side of selected image, before the user clicks on a submit button.
I've found this approach here in the forum:
function selectedPhotoText(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#imagePreview')
.attr('src', e.target.result)
.width(240)
.height(149);
};
reader.readAsDataURL(input.files[0]);
}
else {
$('#imagePreview').attr('src', "../../Images/blqblq.jpg");
}
}
<img id="imagePreview" class="img-border" src="../../Images/blqblq.jpg" alt="Selected Image"/>
and the file upload control:
<asp:FileUpload ID="uploadPhotoDialog" onchange="selectedPhotoText(this)" runat="server"/>
This approach works fine in Chrome, Firefox and Opera. Is there any workarounds for IE and Safari?
Thanks in advance!
Upvotes: 1
Views: 1226
Reputation: 21
Safari to 5.X.X and IE to 9.x.x doesnt support FileReader. Look this. http://caniuse.com/filereader
Upvotes: 2