Working with IframesAn iframe is an inline frame, that is, a frame that can be embedded within a regular HTML page instead of needing to be inside a frameset. Like a regular frame, an iframe is a separate HTML document. You can use an iframe as the target of a script, so you can create content on the fly under script control and display it in the page without having to use a frameset. In this task, we have a regular HTML page with a content area that is an iframe. The content of the iframe is created using JavaScript. Script 5.16 creates the regular page. Script 5.17 is the placeholder HTML document that shows the user the initial content in the iframe, namely the "Please load a page" instruction, as shown in Figure 5.14. That content will be replaced by the product of Script 5.18; when the user clicks one of the links, JavaScript writes out new code to the iframe. In this case, it's displaying the name of the page and how many times the user has gone to that page in this session. As you will see, most of this script is built of pieces you've seen earlier in this chapter. Script 5.16. This page creates the iframe and calls the external JavaScript.Script 5.17. The initial page that goes in the iframe.
Figure 5.14. The iframe, on the right, initially contains an instruction to click a link.Script 5.18. This script calculates the content of the iframe and writes it into the window.
To create the content for an iframe:
Tip
|