SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Resource

Layering Pages

Categories...
Client User Group
Site Design, Write Once!
Language
JavaScript
Product
IE4, NS4
Task
Cross-Browser DHTML, Layout Enhancement
Technology
Dynamic Content

Sponsored Links
Developer's Paradise : Inside Technique :
Layering Pages
Submission by SiteExperts Staff

Go to the resource:
Layering Pages

Add to Assistant

Short Description
Cross-browser technique for creating rich, interactive web pages by layering content.

Long Description
Cross-browser technique for creating rich, interactive web pages. Dynamically load HTML from the server into positioned elements on your web page.

Author
Scott Isaacs
Submission URL
http://www.SiteExperts.com/tips/contents/ts06/page1.asp
Submission Date
Feb 8,1998
 

Discussion and Rate this Resource
Overall Rating: 4.4

HillsCap on Aug 14, 2003 at 8:29:36 PMNo Rating

Hi, all.

We've been using this script for quite a while in our website (http://www.hillscapital.com/). And, I've been trying to get it to work in a cross-browser fashion for quite a while, as well.

I'm trying to make it work only for DOM2 compatible browsers (i.e.: I don't want to support older browsers... it's too much headache. I'm a supporter of the Browser Upgrade Initiative.) I don't want to use innerHTML, as I read on the W3C website that innerHTML is a MS specific kludge that NS adopted at the last moment due to popular demand, and there are no guarantees that it will be supported in future DOM2 compatible browsers. So, I'm trying to work with only DOM2-specific stuff.

Here's the code I've got so far. It doesn't work, and I was wondering if Scott Isaacs or someone else could help me.

var docgetElement = (document.getElementById!=null) //test for newer browsers

function getElement(id) {
// Return the positioned element with the specified ID
  if(docgetElement)
    return document.getElementById(id) //newer browsers
  else if (!docgetElement) { //error message for old browsers
    upgrdmsg = "Your browser does not support the necessary"
    + "\r\n\r\n"
    + "technology to properly view this website."
    + "\r\n\r\n"
    + "Please upgrade your browser.";
    alert(upgrdmsg);
  }
}

function checkIFrame(destID, source) {
    var iframeID = document.getElementByID(destID+"target"); //get iframe ID, if it exists
    if (iframeID==null) { //if not, create it
      iframeID=document.createElement('IFRAME');
      iframeID.setAttribute('id','"+destID+"target');
      iframeID.setAttribute('name','"+destID+"target');
      iframeID.setAttribute('style','border : 0px;');
      iframeID.setAttribute('style','width : 0px;');
      iframeID.setAttribute('style','height : 0px;');
      document.body.appendChild(iframeID);
    }
    iframeID.setAttribute('src',source);
    return iframeID; //send the iframe ID
}

function pollIFrame(destID) {
  var destFrame = checkIFrame(destID); //get iFrame ID
  var fr = document.getElementById('"+destID+"target').cloneNode(true);
    document.getElement(destID).appendChild(fr) //get DIV id and set content equal to iFrame content
  var fr = document.getElementById('"+destID+"target');
    fr.parentNode.removeChild(fr); //remove iFrame (supposed to fix back button problem)

}

function updateContents(destID, source) {
  var el1 = getElement(destID) //get DIV id
  destFrame = checkIFrame(destID) //get iFrame id
  setTimeout("pollIFrame('"+destID+"')",200) //make sure iFrame is ready and update DIV contents
}

function update(destID, source) {
  if (source=="none" || source=="") {
    var el1 = getElement(destID) //get target DIV
    var el1Len=el1.childNodes.length; //count number of Nodes in target DIV
    for (i=0;i<el1Len;i++){
      el1.removeChild(el1.childNodes[0]); //remove all the Nodes in target DIV
    }
  }
  else {
    updateContents(destID, source)
  }
}

 

Some issues:

1) I still can't get it to work!

2)The pollIFrame function can't use readyState because that's an IE specific thing... so another way to determine that the content has been fully loaded into the iFrame has to be used. I'm not sure what to use.

3) The Back button is broken by this code. I'm thinking of implementing a feature where the javascript monitors the SRC attribute of the iFrame, and if it changes (by the user clicking the back button), it will trigger the update function. Of course, you'd also have to keep track of which DIV the content was loaded into.

By updating the code, I hope to:

1) make it work cross-browser

2) make it compatible with any new DOM2 compatible browsers that are released

3) fix the Back button problem

I think once this thing is working in the manner I have envisioned, it will be a widely used script, as it will allow layout that works similar to tables or frames, without the problems that those layouts entail (ie: back button problem, search engine indexing problems, otherly-abled persons accessibility problems, etc.)

I'd like to thank Scott Isaacs for coming up with the script in the first place... it's pure genius, allowing a flexibility and freedom in website design that already solves several problems inherent in Frames and Tables layouts.

vahagn on Jun 20, 2003 at 1:59:02 PMRating: 4
When I run the script I get a error pop up saying "Access denied!" with error on row if (destFrame.document.readyState
=='complete')
I guess it is refering to destFrame since I once got the message for row
el.innerHTML =
destFrame.document.body.innerHTML

when I took the "if" case away. IS there anyone who knows why this happens?
QuantumRadio on May 11, 2002 at 4:26:23 PMRating: 5

In IE it caches the file being loaded, so it never loads a new copy nless you refresh the whole page. In Netscape it works fine, reloading a new file each time.

Isthere some way to make this cross browser compatible ?

 

QuantumRadio on May 10, 2002 at 11:57:30 PMRating: 5

This is an excellent script, and _almost_ does what I want. I'm trying to get it to reload the div but it wont.

It seems to be caching the info.htm file, and won't then reload it until you move away from it, then come back.

..................................

function regularTask() {
 update("Layer1","info1.htm"));
 timerID = setTimeout("regularTask()", 120000);
 }

..................................

This will load the file the first time around, but then never updates it. I have another program that creates info1.htm every few minutes, so it is acutally different, however, the program never wants to reload it.

I tested this easily with the actual demo. if you just switch between the 2 windows with the same file being loaded, it loads once, but then must be caching, and doesn't load the new one, UNLESS you load info2.htm into the div, and then go back and load info1.htm, at which time it loads a new copy of the file.

Is there some way to get the loaded file to not cache like that.? I want the NEW file to load each time its called.

Of course, ideally, I'd like the load to take place only when the info.html file has actually been changed - but I can't find a way to do that.

 

 

 

azrasta on May 16, 2001 at 11:22:25 PMRating: 2

for what I know, if u tried to use this in Netscape, scrollbars aren't available. You would have to construct them yourself. That, of course requires more code.

More Ratings/ Comments


To rate and comment on a resource, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password

Copyright © 1997-2008 InsideDHTML.com, LLC. All rights reserved.