1

I'm looking for something similar to jQuery.holdReady() but using only vanilla JS. I have an iframe that is loading some content asynchronously. And a listener outside of the iframe listening to its load event for a cookie to be set. Is there a vanillaJS way to delay that load event until the cookie is set asynchronously.

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
user3704512
  • 151
  • 10
  • I have a requirement that I have to get the data inside of iframe async-ly to get some data that needs to be set to a cookie. A third party script that i have not control of looks at the cookie in the iframe from the iframe. Another third party listener, listens to the iframe. Sadly it is using an on load listener, so i need to make sure to trigger it only when i have my async cookie. It's not a great situation, but it's the one i'm in. – user3704512 Apr 20 '17 at 06:33
  • Does the onload actually trigger? I would expect you need to set the onload before the iFrame: http://stackoverflow.com/questions/8233278/jquery-onload-load-event-not-working-with-a-dynamically-loaded-iframe – mplungjan Apr 20 '17 at 07:32
  • For jquery, yes it does trigger. Standard dom listeners do not. Again, that piece of code is a blackbox, and is only there to give an idea of the listener style. Suffice it to say, it has some way to communicate with the iframe based on load the dom's load event. – user3704512 Apr 20 '17 at 07:45

0 Answers0