Skip to content

Instantly share code, notes, and snippets.

@pketh
Last active October 25, 2024 10:05
Show Gist options
  • 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()
@Jonghakseo
Copy link

Jonghakseo commented Oct 25, 2024

Missing return at isIOS function

const isIOS = () => {
  return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
}

@pketh
Copy link
Author

pketh commented Oct 25, 2024

You’re right , good catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment