
Originally Posted by
Beagle72
I'm about ready to start working on this again today. I've got 3 good routes to try (jQuery, mootools, hidden div). I'll let you know how it turns out.
In the meantime I'll correct some errors in my previous post, which was written too hastily.
test1.html:
Code:
<head>
<script type="text/javascript">
var pageRequest = false
/*@cc_on
@if (@_jscript_version >= 5)
try {
pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try {
pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e2){
pageRequest = false
}
}
@end
@*/
if (!pageRequest && typeof XMLHttpRequest != 'undefined')
pageRequest = new XMLHttpRequest()
function include(content,id){
var newdiv = document.createElement("div");
newdiv.innerHTML = content;
document.getElementById(id).appendChild(newdiv);
}
if (pageRequest){
pageRequest.open('GET', 'test2.html', false)
pageRequest.send(null); ajax_include=pageRequest.responseText;
document.write('<div style="display:none">');
document.write(ajax_include);
document.write('<\/div>');
}
</script>
</head>
<body >
<div>
What you see above the horizontal line is content from <i>test1.html.</i>. What you see below the horizontal line is content from <i>test2.html.</i> <br><br>
Click <a href="javascript: void(0)" onclick="document.getElementById('div1').innerHTML=''; document.getElementById('div1').style.background='white';document.getElementById('div2').innerHTML=''; document.getElementById('div2').style.background='white'">here</a> to empty the area below the horizontal line.<br><br>
<a href="javascript: void(0)" onclick="load_date()">Execute code from test2.html by directly referencing (in test1.html) a function (=load_date()) that is inside test2.html</a><br>
<a href="javascript: void(0)" onclick="include(ajax_include,'div1')">Import text and code from test2.html with the help of a function (=include(content,id)) that is inside test1.html</a>
</div><hr>
<div id="div1"></div><br>
<div id="div2"></div>
</body>
test2.html:
Code:
<head>
<script type="text/javascript">
function load_date(){
var myDate = new Date();
document.getElementById('div2').innerHTML+='Hello World! The date is: ' + myDate+'<br><br>';
document.getElementById('div2').style.background='red';
document.getElementById('div2').style.color='white';
}
</script>
</head>
<body>
<a href="javascript: void(0)" onclick="load_date()">This link is imported from test2.html. It loads the date using function load_date() (in test2.html)</a>
</body>
Arie.
Bookmarks