JavaScript Include() Function
This is an example of a JavaScript include()
function which uses a hidden iframe to
communicate with the server, or include other files as needed.
In addition to the hidden iframe which is used to
transport the data the script utilises an extra
div element in which it actually copys the data
for display and/or execution.
The script was designed to emulate the PHP include()
function on the client side, allowing the developer to create highly dynamic
pages without access to server side scripting technologies.
The script has some notable limitations detailed below:
- The script can only include files from the same domain.
External files cause JavaScript errors and do not include the
requested page due to the security policies incorperated into
the language.
- The included file type must be natively supported by the browser.
The inclusion of non-natively supported file types will result in a
'Save As...' dialouge box being displayed on most systems. This can
be over come by simply re-naming the file to name.ext.htm
and the file will then be correctly included.
- The browsers default formatting is included.
For some filetypes (such as .txt) the browser applys default
formatting to the file upon opening it. This default formatting
may be copied across into your displayed document. It is recommended
all files to be directly included are renamed using the convention
detailed above where the expected HTML/CSS fornatting will be applied
for display in the resultant document.
Demo
You may include as many files, in any order, as many times as you wish.
Include:
Text,
JavaScript or
CSV