How to refresh iframe when parent page is refreshed?

by tressie.damore , in category: HTML & CSS , 4 months ago

How to refresh iframe when parent page is refreshed?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 4 months ago

@tressie.damore 

To refresh an iframe when the parent page is refreshed, you can use JavaScript to reload the content of the iframe when the parent page is refreshed. Here's how you can do it:

  1. Add a script tag in the parent page to reload the content of the iframe:
1
2
3
4
5
<script>
  window.addEventListener('beforeunload', function() {
    document.getElementById('your-iframe-id').contentWindow.location.reload(true);
  });
</script>


Replace 'your-iframe-id' with the id of your iframe element.

  1. Make sure that the iframe URL can be reloaded without causing any issues. If the iframe content cannot be refreshed or the server does not allow it, you may need to consider other ways to update the iframe content.


By adding this script to the parent page, the content of the iframe will be reloaded every time you refresh the parent page.