Instantly share code, notes, and snippets.

Embed
What would you like to do?
Detect mobile device
<script>
"use strict";
class inputCapture {
constructor(id, style) {
this.id = id
this.style = style
this.element = null
}
create() {
document.body.innerHTML += `<input type="file" capture="camera" id="${this.id}" style="${this.style}">`
this.element = document.getElementById(this.id)
}
remove() {
this.element.parentNode.removeChild(this.element)
}
status() {
return this.element.capture
}
}
let capture = new inputCapture(
'inputCaptureDummy',
'display:none'
)
capture.create()
const capturable = !! capture.status()
capture.remove()
document.body.innerHTML += `I'm a mobile device: ${capturable ? '👍' : '👎'}`
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment