In this second part of a two-part series on the ins and outs of iframes, we will explore more uses for iframes. The ones we will discuss fall into the broad category of remote scripting, or remote procedure calls (RPC). You won't find any sophisticated code in this article, but we will do quite a bit with just plain HTML tags and some basic PHP.
Remote Scripting with iframes - Passing Data from Parent Window to iframe using Query String (Page 3 of 4 )
This time, the first thing that Joe did was change the extension of each of the pages of his site to .php so he could use them with a PHP include. Next, he added a query string to each of his links so that he could send data to the iframe utilizing the Getmethod. Since the Wizards' site had five pages, now the main page with menu and iframe looked something like this:
Now the Wizards' site operated with no page reloads whatsoever! The main page remains loaded in the main window, and "menu.php" remains loaded in the iframe. As Joe clicked on the links of his menu, the page content changed, but the URL displayed in the browser address bar remained that of the main page. The Wizards fan club members were very impressed!
Due to the inability of an iframe to resize itself to accommodate content of various sizes, this method is less than ideal for the purpose of content navigation, unless all of the pages of content are the same size. The example was chosen to illustrate both the advantages and a disadvantage of using iframes for remote scripting.
Ajax request response methods can be used in a similar manner without a problem as far as varying content size, but they suffer from a drawback that the iframe navigation method we described does not. With the iframe method of navigation in the above example, the browser's "Back" button works as expected in most browsers. When the back button is clicked, the content in the iframe reverts to the previous content. The main page remains loaded. This is the behavior that the user probably expects, since it emulates how traditional navigation works.
With request response methods, on the other hand, the back button will probably not work as expected in most browsers. In this case, when the back button is clicked, the main page reverts to the previous main page, which is not what the user would expect. There are workarounds for this problem, but they are ugly.