• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Frames, Frames, and More Fram... > Creating and Loading a Dynamic Frame

Creating and Loading a Dynamic Frame

Because JavaScript can create page content on-the-fly, it's useful for loading dynamic data into frames based on a user's choice in another frame. Script 4.14 is a frameset which loads a dummy content page ( Script 4.16 ) and a navigation page ( Script 4.15, detailed below) that can create a page and load it into the main content frame.

Script 4.15. JavaScript lets you create the HTML on-the-fly, writing new pages as the result of a script.

To load a dynamic frame from another frame:

								function writeContent(thisPage) {
								parent.content.document.write ("<HTML><HEAD><\/HEAD><BODY BGCOLOR='WHITE'><H1>")
								parent.content.document.write ("You are now looking at page "+thisPage+".")
								parent.content.document.write ("<\/H1><\/BODY><\/HTML>")


Create a new function called writeContent(), which, when given a page number, creates a dynamic page and then loads it into the content frame. It does this by finding the parent of the current document, then finding the content frame of the parent document, and then writing the new page into the content document. You finish with document.close() to make sure that everything you've written is displayed.

								<A HREF="javascript:writeContent (1)">Page 1</A>

Within the body of the page, create links to pages that you want loaded into the main window. When the link is clicked, the JavaScript function writeContent() is called and passed the page number (1, in this case) that you want to create and load. Figure 4.9 shows the result. Repeat this line, with a new page number, for each page that you want to create and show in the content frame.

Figure 4.9. And here's the result of Script 4.15, a Web page written by a JavaScript.

Script 4.16. The dummy page that's initially loaded.

Script 4.17. The frameset page loads in our desired frames.

Script 4.18. Write a JavaScript function once and use it on many pages to calculate a random image.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint