Reputation: 1120
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!
Upvotes: 3
Views: 2055
Reputation: 34199
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.
Upvotes: 3