Skip to content

Instantly share code, notes, and snippets.

@pketh
Last active December 23, 2023 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pketh/f6b37564b8f42fca7c61eb43c39287de to your computer and use it in GitHub Desktop.
Save pketh/f6b37564b8f42fca7c61eb43c39287de to your computer and use it in GitHub Desktop.
disable ios text field autozoom
// https://stackoverflow.com/a/57527009
const disableIOSTextFieldZoom = () => {
if (!isIOS()) { return }
const element = document.querySelector('meta[name=viewport]')
if (element !== null) {
let content = element.getAttribute('content')
let scalePattern = /maximum\-scale=[0-9\.]+/g
if (scalePattern.test(content)) {
content = content.replace(scalePattern, 'maximum-scale=1.0')
} else {
content = [content, 'maximum-scale=1.0'].join(', ')
}
element.setAttribute('content', content)
}
}
// https://stackoverflow.com/questions/9038625/detect-if-device-is-ios/9039885#9039885
const isIOS = () => {
/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
}
disableIOSTextFieldZoom()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment