You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS系统下H5调用相机拍照导致浏览器闪退问题求助

iOS下H5调用相机拍照导致浏览器闪退,需实现仅拍照上传禁止本地选择

在iOS系统中,通过H5调用相机拍照时会触发浏览器闪退,已在百度、谷歌搜索许久仍未找到解决方案。

需求明确:仅允许用户通过拍照上传图片,禁止选择本地相册内的图片。

HTML代码

<img src="xxx" onclick="startPhoto"/>

JavaScript代码

startPhoto(){
    document.getElementById( 'inputElementId').click()
}
// 页面加载完成后调用此方法
createInputFile(){
    let input = document.createElement("input")
    input.id = 'inputElementId'
    input.type = 'file'
    input.accept = 'image/*'
    input.capture = 'camera'
    input.onchange = this.photo
    input.style.width = '10px'
    input.style.height = '10px'
    input.style.display = 'none'
    document.getElementById('box').append(input);
},

photo( e){
    const files = e.target.files;
    let file = files[0];
    
    if( !window.FileReader) {
        return '对不起,您的设备不支持上传图片'
    }
    const reader = new FileReader();
    let key = this.choseKey
    reader.onload = (e) => {
        let data = e.target.result;
        
        if(key == 'panorama'){
            this.uploadedImgsPanorama.push( data)
        }else if(key == 'ornaments' ){
            this.uploadedImgsOrnaments.push( data)
        }else if(key == 'equipment' ){
            this.uploadedImgsEquipment.push( data)
        }
    };
    reader.readAsDataURL(file);
},

内容的提问来源于stack exchange,提问作者郭志超

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 06:10:01