Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

refresh iframe from a .php in a separate iframe

I have a page that is built with 7 different iframes:

<iframe id="leftframe" src="structure/leftbar.php"></iframe>
<iframe id="headerframe" src="structure/header.php"></iframe>
<iframe id="menuframe" src="structure/menu.php"></iframe>
<iframe id="timerframe" src="structure/times.php"></iframe>
<iframe id="settingsframe"></iframe>
<iframe id="contentframe" name="contentframe"></iframe>
<iframe id="chatframe" src="chat/index.php"></iframe>

I have a .php that is being run in the "contentframe". When I click a button in it, it sends a post to a .php. The .php functions properly but at the end of it, I want it to reload the leftframe frame.

I tried the suggestions on these pages:

How to refresh an IFrame using Javascript? What's the best way to reload / refresh an iframe using JavaScript?

but neither of these seem to work.

in the .php I am trying:

?>

    <script>
        parent.getElementById('leftframe').location.reload();
        alert("Ping");
    </script>

<?php

This doesn't work either. Any suggestions?

Thanks!

like image 700
jpgerb Avatar asked Apr 01 '26 03:04

jpgerb


1 Answers

Using back-end to refresh an iframe when you can do it client-side is absolutely wrong.

It works for me:

<script>
     document.getElementById('leftFrame').contentWindow.location.reload(); 
     alert('Ping');
</script>

And, yes, are you sure you need iframes?
It is definitely not a good practice. Especially, in a century of powerful JS and its frameworks and AJAX. It would be better if you updated the content of DOM element instead of refreshing iframe.

like image 184
Yeldar Kurmangaliyev Avatar answered Apr 03 '26 17:04

Yeldar Kurmangaliyev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!