Either you use this DD Ajax-script, which uses innerHTML (no document.write) and apply what it says about fetching external js, or you do as explained in the tutorial, where it says: 'If we do not want the menu to appear right away but, say, on click, then we must ...'.
To test the latter possibility:
main.html
Code:
<head>
<style type="text/css">
.inserted{display:none}
</style>
<script type="text/javascript">
document.includeWrite = function (url) {
if ('undefined' == typeof(url)) return false;
if (window.XMLHttpRequest)reqWrite = new XMLHttpRequest()
else if (window.ActiveXObject){
try {
reqWrite = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
reqWrite = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
reqWrite.open("GET",url,false);reqWrite.send(null);
document.write(reqWrite.responseText);
}
</script>
<script type="text/javascript">
function toggle(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = 'inline';
}
}
function hideAll(tag,SomeClass) {
var els = document.getElementsByTagName(tag)
for (i=0;i<els.length; i++) {
if (els.item(i).className == SomeClass){
els.item(i).style.display = 'none';}
}
}
</script>
</head>
<body>
<a href="javascript:void(0)" onclick="hideAll('div','inserted'); toggle('external1')">include external 1</a>
<div id="external1" class="inserted"><script type="text/javascript">document.includeWrite('external1.html')</script> </div>
<br><a href="javascript:void(0)" onclick="hideAll('div','inserted'); toggle('external2')">include external 2</a>
<div id="external2" class="inserted"><script type="text/javascript">document.includeWrite('external2.html')</script> </div>
<br><a href="javascript:void(0)" onclick="hideAll('div','inserted'); toggle('external3')">include external 3</a>
<div id="external3" class="inserted"><script type="text/javascript">document.includeWrite('external3.html')</script> </div>
</body>
external1.html
Code:
This is <a href="javascript:void(0)" onclick="alert('I`m external 1')" style="color:red">external 1</a>
external2.html
Code:
This is <a href="javascript:void(0)" onclick="alert('I`m external 2')" style="color:red">external 2</a>
external3.html
Code:
This is <a href="javascript:void(0)" onclick="alert('I`m external 3')" style="color:red">external 3</a>
Note that if we do a simple document.write after the page has loaded, all existing content will be cleared and replaced by the new content.
===
Arie.
Bookmarks