473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

onload in Safari

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.

-- tim
Jul 23 '05 #1
11 3003
Tim Streater wrote:
I seem to have to delay inside some_script


Why not rather put the <script> at the end of the page after </body>?
Jul 23 '05 #2
bmgz wrote:
Tim Streater wrote:
I seem to have to delay inside some_script

Why not rather put the <script> at the end of the page after </body>?


<script> elements are allowed inside <head> elements and <body> elements,
but not outside them.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #3
David Dorward wrote:
bmgz wrote:
Tim Streater wrote:


I seem to have to delay inside some_script


Why not rather put the <script> at the end of the page after </body>?

<script> elements are allowed inside <head> elements and <body> elements,
but not outside them.

whoops,
Why not rather put the <script> at the end of the page BEFORE </body>?
Jul 23 '05 #4
ASM
David Dorward wrote:
bmgz wrote:
Tim Streater wrote:

Why not rather put the <script> at the end of the page after </body>?

<script> elements are allowed inside <head> elements and <body> elements,
but not outside them.


*not allowed* doesn't mean *forbidden* ;-)

script written after </html> is interpreted ... so ...

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #5
ASM wrote:
<script> elements are allowed inside <head> elements and <body> elements,
but not outside them.
*not allowed* doesn't mean *forbidden* ;-)
Yes it does.
script written after </html> is interpreted ... so ...


So you are depending on browsers to fix your mistakes for you. Which isn't a
good idea.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #6
ASM
David Dorward wrote:
ASM wrote:
script written after </html> is interpreted ... so ...

So you are depending on browsers to fix your mistakes for you. Which isn't a
good idea.


Any way we are talking about JS so ... the dependance ... it'd got :-/

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #7
ASM <st*********************@wanadoo.fr> writes:
David Dorward wrote:
<script> elements are allowed inside <head> elements and <body>
elements,
but not outside them.

*not allowed* doesn't mean *forbidden* ;-)


It doesn't mean "illegal" (the police won't come for you), but it does
mean "invalid" HTML.
script written after </html> is interpreted ... so ...


In some browsers. Maybe even in all existing browsers (but none of us have
tested that, since "all existing browsers" is quite a lot).

Howver, when you use invalid HTML, you depend on all browsers, unknown
and future, to treat the HTML (and DOM and other scripting issues) the
same way as the browsers you have tested with.

If you use valid HTML, you just depend on unknown and future browsers
to follow the standard. That is quite a lot more likely (perhaps with
future versions of IE as an exception :).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #8
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()
}
--
Rob
Jul 23 '05 #9
RobG wrote:
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()
}


By trying to guess the time it takes to load the page, you are dealing
with a completly unknown, unpredictable quatity - kinda like saying how
long is a piece of string. Kludgy? -more like impossible.
Jul 23 '05 #10
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
Jul 23 '05 #11
Tim Streater wrote:
[...]

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>.
I doubt that would help, it should be parsed & start running before
the body onload is run.

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.


Sift through these:
<URL:http://www.quirksmode.org/bugreports/archives/safari/index.html>

or report it as a bug to Apple (you have to create an ADC account, but
it's free and they don't bug you ..).

<URL:http://webkit.opendarwin.org/quality/reporting.html>
--
Rob
Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tery Griffin | last post by:
Hi all, Iıve been away from Javascript for awhile and am rusty, but this is too simple not to work! Iım on a Mac, and usually use the Safari browser. I have a very basic web page in a frame. ...
1
by: bjarthur | last post by:
i have (see below) what i think is a fairly simple algorithm, but yet it doesn't work. given a directory with consecutively numbered jpeg files (1.jpg, 2.jpg, 3.jpg...), it is designed to count...
3
by: usenet | last post by:
Hi All, I have some initialization to be done at page load time, which changes the text of some anchors so that they are consistent with the query string (these anchors are used as criteria...
2
by: Martin Honnen | last post by:
I was playing around with canvas support in recent Safari, Mozilla and Opera (only version 9 preview) but run into issues with Safari related to the very old DOM Level 0 Image object for preloading...
1
by: jamierphelps | last post by:
I'm sure you guys are tired of seeing this kind of message, but this is hopefully something a little different. I searched first. I am using Drupal for a site and I also want to use Nifty Corners...
2
by: cgrady | last post by:
I'm working on part of a larger project, and in trying to debug one aspect, I've got a small test file to work with. The code is practically identical (all important aspects match word for word)...
2
by: RobG | last post by:
There has been a bit of work done to get an init() function to run when the DOM is complete but before all the images have been downloaded. The idea is to kickoff init() scripts when all the...
20
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for...
1
by: zebra242 | last post by:
I'm working to get the onLoad function of a javascript to work: the script allows form buttons in html to refer to labeled frames in flash. Which works fine. Now I want to add onLoad...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.