Skip to content

Instantly share code, notes, and snippets.

@erkobridee
Last active December 15, 2022 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erkobridee/e567d22180b9118229441f71791f6ec7 to your computer and use it in GitHub Desktop.
Save erkobridee/e567d22180b9118229441f71791f6ec7 to your computer and use it in GitHub Desktop.
set focus to an iframe after loads its content
// hack to enable touch after focus on the iframe
html,
body {
touch-action: auto;
}
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;
// 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