我的问题:
然后用户点击input type=file
用户必须获得 upload file + camera
对话。我正在使用这个 html 属性 accept
和 capture
.但在一些现代设备上,这不会发生。下面是代码示例和它的工作与否的表格。代码示例在 Mobile Safari
中进行测试和 Chrome
.
TL;DR:
我有 5 个代码示例,只有 input type file
:
1.( jsfiddle
)
<input type="file" accept="image/*" capture>
2. ( jsfiddle
)
<input type="file" accept="image/*" capture="camera">
3. ( jsfiddle
)
<input type="file" capture="camera">
4. ( jsfiddle
)
<input type="file" capture>
5. ( jsfiddle
)
<input type="file" accept="image/*">
测试设备:
- 三星 S3(Android 4.1.2)
- 三星 S3(Android 4.3)
- 三星 Galaxy Tab 2 7.0 (Android 4.2.2)
- 三星 Note (Android 4.1.2)
- iPhone 5 (iOS 7.0.4)
- Nexus 4 (Android 4.4)
结果表:
- W(ork) - 表示启用
upload image dialog with camera
- P(artially works) - 表示启用
upload dialog(not image only) with camera
- N(ot work) - 表示
only camera
启用 - Ch - 表示
Chrome
- MS - 表示
Mobile Safari
#
--------------------------------------------------------------------------------
|devices/example | Ch 1| Ch 2| Ch 3| Ch 4| Ch 5| MS 1| MS 2| MS 3| MS 4| MS 5|
--------------------------------------------------------------------------------
|Samsung S3/4.1 | N | N | P | P | W | W | N | P | P | W |
--------------------------------------------------------------------------------
|Samsung S3/4.3 | N | N | P | P | P | N | N | P | P | P |
--------------------------------------------------------------------------------
|Samsung Galaxy Tab| N | N | P | P | W | W | N | P | P | W |
--------------------------------------------------------------------------------
|Samsung Note | N | N | P | P | W | W | N | P | P | W |
--------------------------------------------------------------------------------
|iPhone 5 | W | W | P | P | W | W | Y | P | P | W |
--------------------------------------------------------------------------------
|Nexus 4 | N | N | P | P | W | - | - | - | - | - |
--------------------------------------------------------------------------------
如你所见,我只能得到 upload file + camera
使用所有浏览器的对话框
<input type="file" accept="image/*">
只要。但是没有capture
在这种情况下属性,这让我担心,Android 4.3 存在问题。
我的问题是:
- 表中的行为是否正确? Android 4.3 的行为是一个错误?
- 对于浏览器,我可以相信它总是会添加摄像头来上传吗 没有捕获属性的对话框? (答案请添加证明链接)
谢谢。
附:问题很特殊,但在我的网站上,我必须为用户提供对其图像和相机的访问权限。另外我认为我的表格对任何人都有帮助,而且我会寻找答案,如果没有人回答,我会在这里发布我的答案。
最佳答案
这是真正的答案。只需在此处发布以供下一个用户使用:
Actually, it seems that current implementations don’t rely on the capture attribute at all, but only on the type and accept attributes: the browser displays a dialog box in which the user can choose where the file has to be taken, and the
capture
attribute is not taken into consideration. For example, iOS Safari relies on the accept attribute (not capture) for images and videos (not audio). Even if you don't use theaccept
attribute, the browser will let you choose between "Take Photo or Video" and "Choose Existing" (thanks to@firt for pointing this out).
来自 this
2016 年 2 月 17 日编辑: 此行为在设备上仍然有效。
关于android - 具有捕获和接受属性的 HTML 文件输入控件工作错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21523544/