Skip to content

Instantly share code, notes, and snippets.

@ivcreative
Forked from erkobridee/iframe-content.css
Created July 13, 2024 21:57
Show Gist options
  • Save ivcreative/26646f8e935d97321b1111ec3547ef16 to your computer and use it in GitHub Desktop.
Save ivcreative/26646f8e935d97321b1111ec3547ef16 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