3

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!

Community
  • 1
  • 1
jpgerb
  • 1,043
  • 1
  • 9
  • 36
  • 1
    stop using frames for this, it was an ok idea 10 years ago, its just bad now –  Jun 17 '15 at 03:30
  • I tried using `$("#xxx").load();` but it caused frame to load uneven and sometimes the menubar started blinking. This is the first way I've found that is even across the board.. – jpgerb Jun 17 '15 at 03:32

1 Answers1

3

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.

Yeldar Kurmangaliyev
  • 33,467
  • 12
  • 59
  • 101
  • how would you suggest I build the outline? `
    ` instead of `
    – jpgerb Jun 17 '15 at 03:41
  • @jpgerb Yes, exactly. Change your `iframe` grid to `divs` grid. You will be able to style it using CSS and manipulate with it using JS. – Yeldar Kurmangaliyev Jun 17 '15 at 03:43
  • This is how I had it originally and it was causing some problems. i'll revert it back and chance to of the menus around to stop them from blinking. Thanks! – jpgerb Jun 17 '15 at 03:44
  • I would also take another step back to evaluate the advantages of managing left menu, header, timer, etc so dynamically, as opposed to an old-fashioned static document in which these components are templated in by the php based on the request. – Chad Hedgcock Jun 17 '15 at 03:58
  • my main purpose of loading these dynamically was to clean up the code so I'm not repeating everything so much. I can put all of this in to each page, but I wanted to find a cleaner way to do it. When I use `$(#divname).load(/link.php);` it causes a lot of delays and freezes the tab in my browser. – jpgerb Jun 17 '15 at 04:22