So you want to include a file (for instance: 'to_be_included.html') into another file (for instance: 'main.html'), where 'to_be_included.html' should contain functions that write innerHTML to divs contained in 'main.html'?
That is possible. In 'to_be_included.html', put in the head:
Code:
<script type="text/javascript">
function add1(strTag,strClass) {
for (i=0;i<top.document.getElementsByTagName(strTag).length; i++) {
if (top.document.getElementsByTagName(strTag).item(i).className == strClass){
var TheItem=top.document.getElementsByTagName(strTag).item(i);
TheItem.innerHTML = 'Inner1';
}
}
}
function add2(strTag,strClass) {
for (i=0;i<top.document.getElementsByTagName(strTag).length; i++) {
if (top.document.getElementsByTagName(strTag).item(i).className == strClass){
var TheItem=top.document.getElementsByTagName(strTag).item(i);
TheItem.innerHTML = 'Inner2';
}
}
}
</script>
and in the body:
<body onload="add1('div','tag1');add2('div','tag2');">
And this is text from the included file ('to_be_included.html') that added 'Inner1' and 'Inner2' above.
Then in the head of 'main.html':
Code:
<!-- Javascript include -->
<script type="text/javascript">
if(window.opera)
{document.write('<iframe src="to_be_included.html" width="0" height="0" name="menu" ></iframe>');}
else document.write('<object type="text/html" data="to_be_included.html" width="0" height="0" name="menu" ></object>');
function extractMenu(){
try{
document.body.innerHTML+=window.frames['menu'].body.innerHTML;
}
catch(e){
document.body.innerHTML+=window.frames['menu'].document.body.innerHTML;
}
}
window.onload=extractMenu;
</script>
and in the body of 'main.html':
Code:
<body>
<div class="tag1" ></div><br>
<div class="tag2" ></div><br>
...
Note:
I don't know why you want to do what you asked for. If you have special reasons to write content to a main file with the help of functions in an included file, then try my solution. But if all you want to do is multiple onloads, then John's solution (given above) is the simplest one.
===
Arie Molendijk.
Bookmarks