Last active
July 13, 2024 21:57
-
-
Save erkobridee/e567d22180b9118229441f71791f6ec7 to your computer and use it in GitHub Desktop.
set focus to an iframe after loads its content
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
// hack to enable touch after focus on the iframe | |
html, | |
body { | |
touch-action: auto; | |
} |
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
var iframe = window.document.querySelector('iframe'); | |
// ... | |
function isSafari() { | |
var ua = navigator.userAgent.toLowerCase(); | |
return ((ua.indexOf('safari') != -1) && (ua.indexOf('chrome') === -1)); | |
} | |
function setIframeFocus() { | |
iframe.focus(); | |
if(isSafari()) { | |
window.setTimeout(function() { | |
iframe.contentWindow.focus(); | |
}, 100) | |
} | |
} | |
iframe.onload = setIframeFocus; |
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
// way to detect the old and newest iPad's | |
var isIPad = (window.navigator.userAgent.match(/(iPad)/) /* iOS pre 13 */ || | |
(window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1) /* iPad OS 13 */); | |
var isIOS = /iPad|iPhone|iPod/.test(navigator.platform) | |
|| (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment