Home arrow HTML arrow Page 2 - Remote Scripting with iframes
HTML

Remote Scripting with iframes


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.

Author Info:
By: John Best
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
December 22, 2008
TABLE OF CONTENTS:
  1. · Remote Scripting with iframes
  2. · Using iframes for Site Navigation
  3. · Passing Data from Parent Window to iframe using Query String
  4. · Other uses

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Remote Scripting with iframes - Using iframes for Site Navigation
(Page 2 of 4 )

This is a simple example, so let's use my imaginary friend Joe again. He is resourceful but kind of simple-minded. You may recall from part one of this article that Joe is the webmaster for the Web Town Wizards football club.

Joe has received so much praise from the members of the Wizards fan club for the score box that he had put on the Wizards website, that he was getting a big ego. He was beginning to think he could do almost anything using the iframes techniques he had learned. This time, he wanted to do something that would really impress the members.

Joe had seen web pages on other sites where only the content of the center column changed as he clicked on the menu links. He thought that this was really slick, and he wanted the Wizards' site to operate the same way.

He was using a two-column layout with a header and a left column containing the menu links. Joe figured he could make his site work the same as the one he had seen, by putting an iframe in the right-hand column and loading the content of the other site pages to which users navigate into that, instead of into the main window.

First, he created the iframe tag like so:

<iframe src="home.html" name="aname" width = 100% height = 530>

As the source attribute, he used a page called home.html that contained the content he wanted to load into the iframe initially. In part one of this article, we said that the src attribute is required. This is not technically true. Joe could have left out this attribute, but he would have had a blank space in the page where the iframe is, when the page initially loads.

Next, Joe added a target attribute, using the name of the iframe, to each of the menu links on his page. Here is a sample link from his menu:

<a href="anotherpage.html" target="aname">

Now all he had to do was remove the left column and header from the pages that load in the iframe so that they contain only the content he wants in the iframe, and he was done. It looked sort of like this:

Joe tried this, and the page looked pretty ugly, because it had two scroll bars: the normal Windows scrollbar, and an additional scrollbar inside the iframe. Joe found that by making sure that the height of the main parent page did not exceed the height of his browser window, there was no Windows scrollbar, and since the iframe extended all the way to the right-hand side of the page, now the scrollbar within the iframe looked a lot like the Windows scrollbar that it replaced.

This looked pretty good in Joe's browser window, but even Joe realized that in browser windows larger than his, there would be lots of blank space at the bottom of the page, and in browser windows smaller than his, there would have to be Windows scrollbars. Because of this, in order to get the site to look properly on all monitors, Joe had to make all of his pages a fixed size so there would be no scrollbars needed inside the iframe.

You may recall that in part one of this article, we mentioned that the inability of iframes to resize themselves to accommodate content of varying size was a disadvantage for remote scripting. Well this is an example of that disadvantage. This would not be a problem using Ajax request response methods, because they are able to insert the content of the server response into a block-level HTML element such as a <div> that is able to expand or contract, depending on the size of the content.

Joe could live with the problem of having to make all of his pages the same size, but it wasn't really what he was after. It was still a little bit slow because a new page had to load into the iframe each time a menu link was clicked. Joe had an idea to make his site navigation even faster. By now Joe was really getting excited about web design, and he was learning something new, PHP. He saw this as a great opportunity to use his new-found PHP skills to make his site operate  fast and smoothly.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials