Jumat, 15 Maret 2019

Some part of javascript code make chrome hang in Ios

I am using some very simple html5 and js code to take photo by click of a button from mobile browser and send it to web service. This part of code works perfectly in Safari in Ios (Ipad). Also code works perfectly in Chrome browser Desktop and Desktop Mobile mode.

In Chrome browser on Ios;

  • The part I take photo works (Take photo button) and takes photos and shows photo taken on input box no problem yet.
  • When I click Save Photo button, the chrome browser hangs and does not respond.
  • Unfortunately I do not have an Android device to test if this part of code works in Chrome in Android and can not debug Chrome on Ios.

This is the html part:


<tr id="photo-functions-row">
<td></td>
<td>
<div style="max-width:30%">
<label for="take-photo" class="custom-file-upload">
<i class="fa fa-cloud-upload"></i> Take Photo
</label>
<input type="file" accept="image/*" capture="camera" id="take-photo" onchange="readURL(this);" />
<button id="clear-photo" type="button" onclick="clearPhoto();" class="ui-btn ui-btn-inline" style="margin:5px;">Clear Photo</button>
<button id="save-photo" type="button" onclick="savePhoto();" class="ui-btn ui-btn-inline" style="margin:5px;">Save Photo</button>
</div>
</td>
<td>
</td>
</tr>

This is the js part:


function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#img-placeholder')
.attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}


function savePhoto() {
let files = document.getElementById("take-photo").files;
let reader = new FileReader();
reader.readAsDataURL(files[0]);
reader.onload = function (e) {
let base64Image = e.target.result;
console.log(base64Image);
let params = [];
let CalID = calItem.id;
params[0] = CalID;
params[1] = base64Image;
sendPhoto(params);
};
}



function sendPhoto(params) {
var json = jQuery.post(savePhotoWebServiceAddress,
{
jsonData: JSON.stringify(params)
}).done(function (data) {
let photomessage = "";
try {
var obj = jQuery.parseJSON(data);
if (obj != null) {
if (obj.success == true) {
photomessage = photoMessageSuccess;
}
else {
photomessage = photoMessageFailed;
}
}
} catch (e) {
photomessage = "An exception occured: " + e.message;
}
alert(photomessage);
clearPhoto();
});
}

There should be something specific breaking execution in Chrome browser on Ios.



from Some part of javascript code make chrome hang in Ios

Some part of javascript code make chrome hang in Ios Rating: 4.5 Diposkan Oleh: Admin

0 komentar:

Posting Komentar

Popular Posts