Created
June 8, 2022 05:17
-
-
Save loskael/4f5372daef5b06fa271bf32f1694d702 to your computer and use it in GitHub Desktop.
iframe sandbox
This file contains hidden or 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
(function (script, callback) { | |
var iframe = document.createElement('iframe'); | |
var blob = new Blob([`<script>(${script.toString()})();</script>`], { 'type': 'text/html' }); | |
iframe.src = URL.createObjectURL(blob); | |
iframe.style.display = 'none'; | |
iframe.onload = function () { | |
typeof callback === 'function' && callback(iframe.contentWindow); | |
}; | |
document.body.appendChild(iframe); | |
})( | |
function () { | |
window.r = Math.random(); | |
}, | |
function (win) { | |
console.log(win.r); | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment