Home > Articles > Programming > Java

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close WindowIvan Pepelnjak

Ivan Pepelnjak

Learn more…

Find Facebook Friends with Your Facebook Connect Application
Dec 28, 2009
Publish Your Application Stories to Facebook
Oct 21, 2009
Use Facebook Connect to Bring Your Application to Millions of Users
Aug 31, 2009
Developing AJAX Applications with jQuery
Jun 30, 2009
Web Page Refactoring with jQuery
Jun 10, 2009
Introduction to jQuery: Use jQuery to Write Simpler, Shorter, More Readable JavaScript Code
Jun 1, 2009
Testing Your Website in a Realistic Environment
Aug 5, 2008
Fix Your Web Site Performance Problems
Jul 30, 2008
Why Is My Web Site So Slow for Global Visitors?
Jul 21, 2008
Generating Atom Feed from SQL Data
Mar 31, 2008
Implementing Access Controls on SQL Server Data
Mar 14, 2008
Make Your Web Pages Mobile-Friendly
Jan 18, 2008
Use Google as Your Gateway to the Mobile Internet
Dec 28, 2007
Enhance Your AJAX Applications with Visual Cues
Dec 14, 2007
Building Modal Dialogs into Your Web Application
Nov 9, 2007
Adding Keyboard Shortcuts to Your Web User Interface
Nov 2, 2007
XML Handling in Microsoft SQL Server 2005
Oct 19, 2007
Storing XML Data in a Relational Database
Oct 5, 2007
Serve SQL Data in XML Format
Sep 28, 2007
Enrich Your HTML Tables with JavaScript Progressive Enhancement
Sep 7, 2007
Introduction to HIJAX
Aug 24, 2007
Seven Common CSS Mistakes and How to Avoid Them
Jul 20, 2007
JavaScript Progressive Enhancement in Practice
Jun 15, 2007
Make Pop-Up Windows Visible to Search Engines
Feb 16, 2007
Automate the Pagination of Your Web Pages
Feb 2, 2007
Using WordProcessingML to Generate Clean HTML from Word
Jan 26, 2007
Optimized Presentation of XML Content
Dec 15, 2006
Reap the Benefits of Web Caching, Part 3: Database Integration
Nov 22, 2006
Reap the Benefits of Web Caching, Part 2: Reduce the Download Time
Nov 17, 2006
Reap the Benefits of Web Caching, Part 1: Explicit Content Expiration
Oct 27, 2006
Improve Your Search Engine Ranking with AJAX
Jul 28, 2006
Using Multicast Domains
Jun 27, 2003
Should I Be Interested in MPLS Traffic Engineering?
Jan 3, 2003
Is Troubleshooting Important?
Dec 27, 2002
MPLS/VPN Architecture Overview
Aug 2, 2002
Multiprotocol Label Switching (MPLS) Architecture Overview
Jan 1, 2001
JavaScript Modal Dialog Box in a Frameset Environment
By on December 12, 2007 1 Comment

Only a few modifications are needed to adapt the solution I've described in the Building Modal Dialogs into Your Web Application to a frameset environment.

Sams Teach Yourself Ajax in 10 Minutes

Like this article? We recommend
Sams Teach Yourself Ajax in 10 Minutes

Inline Frames

You should use inline frames if you're concerned about browser compatibility. Some older browsers support IFRAME elements, but not the XmlHttpRequest object. There are also a few other reasons to use this approach:

  • The content being loaded into an IFRAME is displayed in the browser during the loading process, giving the end user a visual indication of progress.

  • Page caching always works with the content loaded into an IFRAME. Some versions of Opera are not very good at handling cached responses with the XmlHttpRequest object.

To implement this solution, insert an empty IFRAME into each DIV container and add a short JavaScript statement after each IFRAME, as follows:

<div id="header">
  <div style="height: 100px; width: 100%"></div>
  <iframe id="header_iframe" style="height: 0px;"></iframe>
  <script>loadIframe("header","/navigation/header.html")</script>
</div>

The id of the IFRAME should be equal to the id of the placeholder suffixed by _iframe. The loadIframe function takes two arguments: the id of the placeholder and the URL to load into it.

The loadIframe function that starts the load process is very simple:

function loadIframe(id,url) {
  try {
    var iframeObj = document.getElementById(id+"_iframe");
    iframeObj.src = url ;
  } catch (err) {
    alert("cannot load "+url+" into "+id) ;
  }
}

However, there's no mechanism to notify the requesting page that the desired content has been loaded into the placeholder IFRAME. The loaded content thus has to notify the parent page (via a JavaScript call) that it's ready to be used. The best moment to do this is after the page load has finished. The BODY tag in the IFRAME content should thus contain an onLoad event:

<body onload="contentLoaded('header')" style="margin: 0px 0px;
padding: 0px 0px">

The contentLoaded function executed in the context of the IFRAME will extract the HTML content of the body and pass it to a function executing in the context of the parent page, which will use it to populate the placeholder:

  • contentLoaded, executed in the IFRAME context:

    function contentLoaded(parentID) {
      var myContent = document.body.innerHTML ;
      parent.copyContent(parentID,myContent);
    }
  • copyContent, executed in the context of the parent web page:

    function copyContent(id,content) {
      try {
        var placeholder = document.getElementById(id) ;
        placeholder.innerHTML = content;
      } catch (err) {
        alert("Cannot copy HTML content into "+id);
      }
    }

A careful reader should wonder by now about the reasons for this complexity—wouldn't it be simpler to load the navigational content in the IFRAME elements? As it turns out, there are a few caveats with that simplistic approach:

  • IFRAME has fixed height and width. If the content exceeds one or the other, it gets cropped or the IFRAME gets "decorated" with the scroll bars. HTML markup copied into a DIV element in the parent page is always perfectly sized.

  • When left within an IFRAME, the links (A elements) in the navigation content would load new pages within the IFRAME (unless you append target="_parent" to each link).

  • JavaScript event handlers attached to navigation elements would work within the context of IFRAME if left there. If you move the navigational content to the main page, the event handlers get access to functions and variables defined within the main page.

  • Share ThisShare This
  • Your Account

Discussions

Make a New Comment

You must log in in order to post a comment.

Related Resources

Jennifer  BortelWin FREE iPhone Developer Books and Videos- Introducing @InformIT Giveaways
By Jennifer Bortel on February 5, 2010 No Comments

Apples’s recent iPad announcement made our hearts flutter so we couldn’t resist making an announcement of our own!

Today marks the first ever @InformIT Giveaway!

We’ll regularly post a video like this one profiling spectacular prizes we’re giving away—from books and videos to T-shirts and other exciting stuff. Check out the video below to see the giveaways for today, and then scroll down for more prize details and instructions on how to win them!

Dustin Sullivan"Every OSX developer should have this book on their desk."
By Dustin Sullivan on February 1, 2010 No Comments

That was the sentence Mike Riley ended his recent Dr Dobb's CodeTalk review of Cocoa Programming Developer's Handbook with.

David ChisnallCocoa Tip of the Day, 1/29/10
By David Chisnall on January 29, 2010 No Comments

Don't ignore old versions of OS X.

See All Related Blogs

Informit Network