-
-
Save ivcreative/26646f8e935d97321b1111ec3547ef16 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