Skip to content

Instantly share code, notes, and snippets.

@confraria
Created May 7, 2020 21:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save confraria/094c3d09e246b70e7ccaf73bc2c47222 to your computer and use it in GitHub Desktop.
Save confraria/094c3d09e246b70e7ccaf73bc2c47222 to your computer and use it in GitHub Desktop.
aaa
function iFrameFix(aId, divId) {
const $a = document.getElementById(aId);
const $div = document.getElementById(divId);
const renderIframe = (img = {}) => {
const w = img.naturalWidth || 100;
const h = img.naturalHeight || 100;
$div.innerHTML = `<iframe src="${a.href}" frameborder=0 width="${w}" height="${h}"></iframe>`;
};
if ($a !== null && $div !== null) {
let img = div.querySelector("img");
if (img) {
if (img.complete) {
renderIframe(img);
} else {
img.addEventListener("load", () => renderIframe(img));
}
} else {
renderIframe();
}
}
}
iframeFix("iframe_A", "iframe_DIV");
iframeFix("iframeLink", "iframeDiv");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment