首页 > 解决方案 > javascript 代码的某些部分使 chrome 在 Ios 中挂起

问题描述

我正在使用一些非常简单的 html5 和 js 代码通过单击移动浏览器中的按钮来拍照并将其发送到 Web 服务。这部分代码在 iOS (Ipad) 的 Safari 中完美运行。此外,代码在 Chrome 浏览器桌面和桌面移动模式下也能完美运行。

在 iOS 上的 Chrome 浏览器中;

这是html部分:

<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>

这是js部分:

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();
        });
}

在 Ios 上的 Chrome 浏览器中应该有一些特定的中断执行。

标签: javascriptioshtmlgoogle-chrome

解决方案


这一切都取决于您拍摄的图像的大小、您从哪个应用程序以及您拥有的 iPad 代。你有什么品种?它还取决于您的 CPU/RAM。即使它来自相机,RAM 也会在其中发挥重要作用。此外,谷歌可能不小心创建了一个导致 iOS 设备挂起的错误。如果有的话,去检查你的 iPad 和 iOS 的更新。此外,您可以尝试启用页面刷新。


推荐阅读