<?php defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' ); ?>
<div class="response-message no-radius no-mb"><?php echo alert_message(); ?></div>

<div id="frameBody">
  <p class="text-center p-3">
    <i class="fa fa-spinner fa-spin"></i>
  </p>
</div>

<script>
  function createFrameElement(src, onLoad) {
    const frame = document.createElement('iframe');
    frame.src = src;
    
    frame.style.height = "0";

    frame.onload = (event) => {
      frame.style.width = "100%";
      frame.style.height = "calc(100vh - 77.5px)";
    }
    onLoad(frame)
  }

  async function loadFrame() {
    const frameTop = document.getElementById('frameBody');
    try {
      const url = "<?php echo base_url('blog/homepage') ?>";
      const response = await fetch(url)
      if(response.ok) {
        createFrameElement(url, (element) => {
          frameTop.innerHTML = '';
          frameTop.appendChild(element);
        });
      }
    } catch(err) {
      console.log(err)
    }
  }

  loadFrame();
</script>