Link to home
Start Free TrialLog in
Avatar of finaris
finarisFlag for Germany

asked on

Including content in a HTML page

Hello Experts,

I would like to split a HTML based report into multiple parts (due to structural reasons).

The aim is to have a main HTML document, which includes data from other text/html files in the same directory.

As there is no INCLUDE command for plain HTML like in PHP (#include(<file>)), I need another solution for this.

Is it possible to include that data dynamically using a scripting language like JavaScript or using a similar approach?
If so, an example would be useful for me.


Please note:
- I have to deal with a very restrictive desktop environment which does not allow me to install additional software, or create/edit registry keys.
- If possible, the solution should be applicable on various operating systems (Windows, Linux, etc.)
ASKER CERTIFIED SOLUTION
Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello:
You could use an XSLT transform to modify the original html file. This solution is fast, doesn't require higher privileges and is inter-operable
Actually, there is an include directive for HTML files if your server is configured for it. Most are, but you may have to have a play around to figure out if yours is.

In your HTML file, you include a file like so:

<!--#include virtual="file-to-include.html" -->

It's called SSI (server side includes).

You may have to rename the extension of your file to shtml, depending on your server's setup.
Noting that you posted this question in the PHP Zone, do you have PHP available to you?  If so, you can use PHP to generate the HTML (as well as access the data model, receive and process client inputs, etc.)

See http://www.laprbass.com/RAY_html5.php
<?php // RAY_html5.php
error_reporting(E_ALL);

// CREATE A VARIABLE FOR OUR HTML
$xyz = 'Hello World';

// CREATE OUR WEB PAGE IN HTML5 FORMAT
$htm = <<<HTML5
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="iso-8859-1" />
<meta http-equiv="Expires" content="Mon, 01 Jan 1990 01:00:00 GMT" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<title>HTML5 Page</title>
</head>
<body>
<p>$xyz</p>
</body>
</html>
HTML5;

// RENDER THE WEB PAGE
echo $htm;

Open in new window