De her to filer simulerer en php include i JavaScript
html fil:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1;">
<META HTTP-EQUIV="CONTENT-LANGUAGE" CONTENT="dk">
<title>Include test</title>
</head>
<script type="text/javascript">
function include(script_filename) {
var html_doc = document.getElementsByTagName('head').item(0);
if (js_file) html_doc.removeChild(js);
var js_file = document.createElement('script');
js_file.setAttribute('language', 'javascript');
js_file.setAttribute('type', 'text/javascript');
js_file.setAttribute('src', script_filename);
if (html_doc.appendChild(js_file)) return js_file;
return false;
}
</script>
<body>
menu:
<script type="text/javascript">
include('include.php')
</script>
<div id="menu"></div>
<br />resten af siden:<br />
Noget tekst bla. bla...
</body>
</html>
include php:
<?php
// javascript header
header('Content-type: text/javascript');
// Date in the past
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// always modified
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
// HTTP/1.1
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
echo('
function menu(obj,html,navn)
{
newElement = document.createElement("a");
newElement.setAttribute("href", html);
newText = document.createTextNode(navn);
newElement.appendChild(newText);
obj.appendChild(newElement);
}
oMenu = document.getElementById("menu");
menu(oMenu,"
http://www.eksperten.dk","Eksperten");
');
?>