P
PaPa
I'm working on a web based presentation of my basic HTML Adult
Education course.
In the middle of the page, I use some javascript to open a window.
<script type="text/javascript">
var fam5=window.open("fam5.htm","fam5", 'width=500 height=500,
scrollbars=1, location=1, menubar=1, resizable=1, toolbar=1, left=20,
top=20');
</script>
fam5.htm is a simple web page that contains a DIV with the id,
"maindiv". I wanted to form a string variable with maindiv's
innerHTML. So, after a lot of irrelevant html, near the end of the
program I put these lines in to see if it would work.
<script type="text/javascript">
var str5=fam5.document.getElementById("maindiv").innerHTML;
alert(str5);
</script>
When I ran the presentation, the window (fam5) opened as I expected,
but I did not get an alert box. My Mozilla Error Console reads:
Error: fam5.document.getElementById("maindiv") is null
I ran another test to see if I was reaching the last lines of code. I
added a second alert box like this:
<script type="text/javascript">
alert('you made it here')
var str5=fam5.document.getElementById("maindiv").innerHTML;
alert(str5);
</script>
When I reran the presentation, I reached the "you made it here" alert
box, but to my surprise, when I clicked OK, the str5 alert box came on
with the proper string. It appears that, somehow, stopping for the
"you made it here" alert allowed the variable str5 to get set up
properly.
There must be something basic about the timing of events that I am
missing. Can someone point me to an appropriate source of
information?
Please keep it basic for this feeble old brain.
PaPa
Education course.
In the middle of the page, I use some javascript to open a window.
<script type="text/javascript">
var fam5=window.open("fam5.htm","fam5", 'width=500 height=500,
scrollbars=1, location=1, menubar=1, resizable=1, toolbar=1, left=20,
top=20');
</script>
fam5.htm is a simple web page that contains a DIV with the id,
"maindiv". I wanted to form a string variable with maindiv's
innerHTML. So, after a lot of irrelevant html, near the end of the
program I put these lines in to see if it would work.
<script type="text/javascript">
var str5=fam5.document.getElementById("maindiv").innerHTML;
alert(str5);
</script>
When I ran the presentation, the window (fam5) opened as I expected,
but I did not get an alert box. My Mozilla Error Console reads:
Error: fam5.document.getElementById("maindiv") is null
I ran another test to see if I was reaching the last lines of code. I
added a second alert box like this:
<script type="text/javascript">
alert('you made it here')
var str5=fam5.document.getElementById("maindiv").innerHTML;
alert(str5);
</script>
When I reran the presentation, I reached the "you made it here" alert
box, but to my surprise, when I clicked OK, the str5 alert box came on
with the proper string. It appears that, somehow, stopping for the
"you made it here" alert allowed the variable str5 to get set up
properly.
There must be something basic about the timing of events that I am
missing. Can someone point me to an appropriate source of
information?
Please keep it basic for this feeble old brain.
PaPa