Including content in a HTML page

finaris
finaris used Ask the Experts™
on
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.)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Systems Manager
Top Expert 2012
Commented:
You can make an ajax call to get the other html and replace the innerHTML of a div.

jQuery does all this for you with a one liner - http://api.jquery.com/load/

jQuery is not adding software to the machine, it's just a case of including a js file in the header and then making a call like:

$("#results").load("myhtml.html");

where your div's id is results, and the html file you want to load is called myhtml.html.


Good Luck

Jon
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
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
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.
Most Valuable Expert 2011
Top Expert 2016

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial