我正在寻找类似于jQuery.holdReady()的东西,但只使用vanilla JS。我有一个异步加载一些内容的iframe。并且iframe外部的监听器监听其load事件以设置cookie。是否有vanillaJS方法来延迟加载事件,直到cookie被异步设置。
myiframe.html
<script>
asyncFunction().then(() => {
document.cookie = 'mycookie=value";
// I have to load a third party script after i set the cookie async-ly
appendThirdPartyScriptThatReadsCookie(); // blackbox
manuallyFireLoadEvent(); // if i could use jquery in the frame: jQuery.holdReady()
});
</script>
mainpage.html
<iframe src="myiframe.html">
//I cannot control the way this page listens for the cookie from the iframe.
$('iframe').on('load', () => console.log(document.cookie)); // blackbox