Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.