javascript - javascript 代码的某些部分使 chrome 在 Ios 中挂起
问题描述
我正在使用一些非常简单的 html5 和 js 代码通过单击移动浏览器中的按钮来拍照并将其发送到 Web 服务。这部分代码在 iOS (Ipad) 的 Safari 中完美运行。此外,代码在 Chrome 浏览器桌面和桌面移动模式下也能完美运行。
在 iOS 上的 Chrome 浏览器中;
- 我拍照的部分(拍照按钮)并拍照并显示在输入框上拍摄的照片还没有问题。
- 当我单击保存照片按钮时,chrome 浏览器挂起并且没有响应。
- 不幸的是,我没有 Android 设备来测试这部分代码是否可以在 Android 的 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 浏览器中应该有一些特定的中断执行。
解决方案
这一切都取决于您拍摄的图像的大小、您从哪个应用程序以及您拥有的 iPad 代。你有什么品种?它还取决于您的 CPU/RAM。即使它来自相机,RAM 也会在其中发挥重要作用。此外,谷歌可能不小心创建了一个导致 iOS 设备挂起的错误。如果有的话,去检查你的 iPad 和 iOS 的更新。此外,您可以尝试启用页面刷新。
推荐阅读
- powershell - 获取 Windows 的集群详细信息
- apache - 服务 httpd restart 不显示任何信息
- c# - 在 C# 中使用内部联接语句将 nvarchar 值转换为数据类型 int 时转换失败
- selenium - 如何在 selenium 网格节点中打开本地计算机中可用的 html 文件
- c# - 将表达式谓词的左侧转换为字符串
- java - 覆盖 URLConnection 的 getInputStream 以通过自定义协议接收数据
- python - 如何将 R 的 .rdata 文件加载到 Python 中?
- hyperledger-fabric - Hyperledger Fabric 链码抛出 MVCC_READ_CONFLICT
- python - TensorFlow:损失函数模块化设计
- javascript - 是否可以在 beforeDestroy 钩子中运行关闭动画?