A Window-based Document Loader
Introduction
Loading documents either as components of a web application or
for use in pre-fetching requires reliable notification of when
the documents are available.
WDocumentLoader provides an easy to use, cross-browser
means of loading documents which
works in Netscape 4.x, Netscape 6, Netscape 7, Mozilla, all Gecko-based browsers, Internet Explorer
and Opera™.
WDocumentLoader.html
extends a normal window object
with several properties and functions
which can be used inside an IFRAME or customized to be
the main page of a web application.
WDocumentLoader.html uses CFormData
to handle processing of the query strings used to specify
the documents to be loaded.
Synopsis
- Properties
-
- document.location.search
-
document.location.searchcontains the query string used to specify the files to be loaded. Each file is specified as the value of a file variable as in:?file=URL1&file=URL2&...&file=URLn
To load a set of documents using
WDocumentLoader, simply loadWDocumentLoader.html?file=URL1&file=URL2&...&file=URLnin an external window,FRAMEorIFRAME.Note that additional information can be passed via the query string.
- Boolean gDataLoaded
-
gDataLoadedis set totruewhen theonloadevent handler is called for theFRAMESETcontaining the documents to be loaded. - CFormData gFormData
-
gFormDatais an instance of theCFormDataJavaScript object which is used to process the query string specifying which documents are to be loaded.
- Functions
-
- handleDataLoad
-
handleDataLoadis called by when the load event fires for the theFRAMESETs. It sets the global variablegDataLoadedtotrue, and calls theWDocumentLoaderCallbackfunction defined in either theparentoropenerwindow if it exists.June 13, 2003 update It is now possible to pass the name of the callback function to the
WDocumentLoaderin the form:?callbackfunction=functionName&file=URL1&file=URL2&...&file=URLn
- outputFrameset()
-
outputFrameset()usesdocument.writeto output aFRAMESETcontaining aFRAMEfor each file specified in the query string used to loadWDocumentLoader.html. - getWindowByIndex(Number aIndex)
-
getWindowByIndex()returns a reference to theaIndexth loaded window. - getWindowByFileName(String aFileName)
-
getWindowByFileName()returns a reference to the loaded window containing fileaFileName.
Example 1
Load a single file.
var documentLoader;
function WDocumentLoaderCallback()
{
var message = 'Loaded: ';
var files = documentLoader.gFormData.getValue('file');
// if there is only one value, it is return as a simple
// value. Since we are reusing this function to handle both
// single values and multiple values, we convert a single value
// back to an array for exposition purposes
if (typeof(files) == 'string')
{
files = [ files ];
}
for (var i = 0; i < files.length; ++i)
{
if (i != 0)
{
message += ', ';
}
message += files[i];
// compare returned window values
if (documentLoader.getWindowByIndex(i) != documentLoader.getWindowByFileName(files[i]))
{
alert('there has been an error in getWindowByIndex/getWindowByFileName');
}
}
alert(message);
documentLoader.focus();
}
function doExample1()
{
var querystring = 'WDocumentLoader.html?file=http://devedge.netscape.com/';
documentLoader = window.open(querystring, 'example', 'height=500,width=500,status=1,resizable=1');
}
This example works in Netscape 6.x, Netscape 7.x, Mozilla, all Gecko-based browsers, Internet Explorer and Opera 7.
Note that Netscape Navigator 4.x does not load a single document however does load more than one reliably.
Example 2
Load two documents.
function doExample2()
{
var querystring = 'WDocumentLoader.html?file=http://www.netscape.com/&file=http://www.cnn.com/';
documentLoader = window.open(querystring, 'example', 'height=500,width=500,status=1,resizable=1');
}
This example works in Netscape 4.x, Netscape 6.x, Netscape 7.x, Mozilla, all Gecko-based browsers, Internet Explorer and Opera 7.
Example 3
Load two documents.
function myCallback(formData)
{
alert('My Callback says ' + formData.getValue('file'));
}
function doExample3()
{
var querystring = 'WDocumentLoader.html?callbackfunction=myCallback&file=http://www.netscape.com/&file=http://www.cnn.com/';
documentLoader = window.open(querystring, 'example', 'height=500,width=500,status=1,resizable=1');
}
