您無法通過input
按鈕執行此操作。
您的替代方案是通過網頁上的相機捕捉圖像,類似於下面的內容,然後將圖像推送到您的服務器。
HTML
<video id="video" width="640" height="480" autoplay></video>
<button id="snap">Snap Photo</button>
<canvas id="canvas" width="640" height="480"></canvas>
的Javascript
// Grab elements, create settings, etc.
var video = document.getElementById('video');
// Get access to the camera!
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
// Not adding `{ audio: true }` since we only want video now
navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
});
}
// Elements for taking the snapshot
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var video = document.getElementById('video');
// Trigger photo take
document.getElementById("snap").addEventListener("click", function() {
context.drawImage(video, 0, 0, 640, 480);
});
來源:https://davidwalsh.name/browser-camera
只是要清楚,你要強迫用戶拍照?或者你會允許其他應用程序,只是沒有照片庫和icloud? – Milk
@Milk如果網頁在ipad中打開,強制它拍照。 –