Last active
October 25, 2024 10:05
-
-
Save pketh/f6b37564b8f42fca7c61eb43c39287de to your computer and use it in GitHub Desktop.
disable ios text field autozoom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
Missing return at
isIOS
function