In article
<42***********************@per-qv1-newsreader-01.iinet.net.au>,
RobG <rg***@iinet.net.auau> wrote:
Tim Streater wrote: I thought that if I have:
...
<body onload="some_script();">
...
that some_script would not be called until the <body> was completely
loaded - is this not the case? With Safari 1.3 I seem to have to delay
inside some_script (there is some php in the <body> that slows down the
loading). Since I happen to have a spare iframe in my <body>, I load a
tiny bit of html in it whose job is simply to set a "loaded" flag,
tested inside my delay code.
What I was observing was that some fields inside a <form> in the <body>,
whose values are set by some_script, were, with Safari, not visible
until I clicked in one of them - then they all popped into sight. I
wasn't seeing this with other browsers and a delay mechanism fixed it.
It was as if the onload was triggered as soon as it was encountered
rather than when the loading was complete.
Got a link or sample?
Maybe use setTimeout() to run the script say 50 milliseconds after
onload (though that seems kinda kludgy), something like:
if ( theForm ) {
// run script
} else {
// run using setTimeout()
}
Here's a (cut-down) sample:
<html><head>
<script type="text/javascript">
function some_script ()
{
document.forms[0].formitem.value = "some text";
}
</script>
</head>
<body class=mtext onload="some_script();">
<form><input readonly name="formitem" type=text size=20></form>
<?
(here is lots of PHP which reads stuff from a mysql database and
eventually echoes some stuff)
?>
<iframe blah blah blah>
</body></html>
I guess I could put some_script just before the </body>.
What I did in the end was to cause some_script to start a delay, which
when complete checked a flag and either restarted the delay or called
some_script again.
The flag is set inside the <iframe> I happen to have available.
But I'm less concerned about the precise details of a workaround, as
understanding just what the onload for a <body> is supposed to do. The
docs I have insist it fires after loading is complete, but I am no
convinced.
-- tim