By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,607 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

onLoad not triggering in IE

P: n/a
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. All it does is trigger a Perl
script. Works great in Safari, does not work in IE or Netscape. In IE, the
onLoad just doesnıt seem to fire. Iıve got to be looking right at the
reason, but Iım not seeing it. Help?

(The live frameset is at
http://www.wsc.ma.edu/webstudents/Co...e_frameset.htm .)

TIA,
Tery

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>comm test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<SCRIPT language="JavaScript">
function submitform()
{
document.form.submit();
}
</SCRIPT>

</head>

<body bgcolor="#330099" onLoad="submitform()">

<form name="form" action="randomimages_2.pl">
</form>
</body>
</html>

Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
In article <BC**********************@cox.net>, Tery Griffin
<te********@cox.net> wrote:
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. All it does is trigger a Perl
script. Works great in Safari, does not work in IE or Netscape. In IE, the
onLoad just doesnıt seem to fire. Iıve got to be looking right at the
reason, but Iım not seeing it. Help?

(The live frameset is at
http://www.wsc.ma.edu/webstudents/Co...e_frameset.htm .)

TIA,
Tery

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>comm test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<SCRIPT language="JavaScript">
function submitform()
{
document.form.submit();
}
</SCRIPT>

</head>

<body bgcolor="#330099" onLoad="submitform()">

<form name="form" action="randomimages_2.pl">
</form>
</body>
</html>

It triggers in both IE5.1 and Netscape7.0 on my Mac with system 9 but
you should add type="text/javascript" to the script tag.
Also check if onLoad should be onload. All tags should be lowercase.

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #2

P: n/a
On 4/24/04 9:32 PM, in article 24*************************@domain.invalid,
"Dennis M. Marks" <de******@domain.invalid> wrote:
It triggers in both IE5.1 and Netscape7.0 on my Mac with system 9 but
you should add type="text/javascript" to the script tag.
Also check if onLoad should be onload. All tags should be lowercase.

Thanks Dennis. I made both changes. No difference for me. I'm on OS
X.2.8, IE 5.3, Netscape 7.1. I'll be this happened with the switch to OS X.

Tery

Jul 23 '05 #3

P: n/a
Terry,

I pretty much avoid using onLoad events any where. There always seems
to be one browser that fails. Currently there is an open bug with
Mozilla that I've been tracking - 99820.

Instead now I now just add my own onLoad call. The following code
after the closing body tag:

<script>
// Your'e onload script here.
</script>

I've had this on production and tested it on Mozilla (OSX, win32,
Linux), IE (win32).

There should be no reason that it will not work in Safari or IE Mac.

BTW - For Cleanliness, I usually add a bodyLoaded function at the top
of the page or in a JS file and call it from the script tag after the
close body tag.

Regards,

Tim
Jul 23 '05 #4

P: n/a
Java script Dude wrote:
<snip>
Instead now I now just add my own onLoad call. The following code
after the closing body tag: ^^^^^
<script>
// Your'e onload script here.
</script>
The HTML DTDs do not allow script elements to appear as children of the
HTML element. The result of doing this is invalid HTML mark-up.
I've had this on production and tested it on Mozilla (OSX, win32,
Linux), IE (win32).

There should be no reason that it will not work in Safari or IE Mac.

<snip>

There is every reason for expecting it to fail; if not in Safari or Mac
IE then somewhere. There are no rules for the handling of invalid
mark-up by web browsers so the browser is a liberty to do anything,
including ignoring the out of context script element, and nobody could
say it is wrong for it to do so. Relying on browser error-correcting
cannot reasonably be recommended as a technique for achieving reliable
results.

Richard.
Jul 23 '05 #5

P: n/a
> Richard Cornford wrote:
Java script Dude wrote:
<snip>
Instead now I now just add my own onLoad call. The following code
after the closing body tag:

^^^^^

<script>
// Your'e onload script here.
</script>


There is every reason for expecting it to fail; if not in Safari or Mac
IE then somewhere. There are no rules for the handling of invalid
mark-up by web browsers so the browser is a liberty to do anything,
including ignoring the out of context script element, and nobody could
say it is wrong for it to do so. Relying on browser error-correcting
cannot reasonably be recommended as a technique for achieving reliable
results.


I agree. If the end goal of the page is to work in a majority of the
browsers that request it, this is not a good technique. But I think we
are still years away when we (as developers) can make complex DHTML
applications that work in a majority of browsers. To build really
maintainable and effective DHTML Apps, the compatible browser list
must be narrowed.

At this time, Mozilla and IE never complain about putting code there
and I am pretty sure with enough nagging, W3C could be convinced that
it's not such a bad idea to allow script tags after the closing body
tag. I have not had the time, nor the need, to test multiple browsers
compatibility. Just IE 5.5sp2+ and Moz 1.3+. At least this could be
used as a back door to the body's onload event.

Maybe I'm way off here ?:]
Jul 23 '05 #6

P: n/a
Java script Dude wrote:
Richard Cornford wrote:
Java script Dude wrote:
<snip>
Instead now I now just add my own onLoad call. The following code
after the closing body tag: ^^^^^

<script>
// Your'e onload script here.
</script>

You have edited my post here without indicating that you have done so,
moving my response to a direct statement of yours out of its original
context.
There is every reason for expecting it to fail; if not in Safari or
Mac IE then somewhere. There are no rules for the handling of invalid
mark-up by web browsers so the browser is a liberty to do anything,
including ignoring the out of context script element, and nobody
could say it is wrong for it to do so. Relying on browser
error-correcting cannot reasonably be recommended as a technique for
achieving reliable results.


I agree. If the end goal of the page is to work in a majority of the
browsers that request it, this is not a good technique. But I think we
are still years away when we (as developers) can make complex DHTML
applications that work in a majority of browsers.


That depends on how you define the majority of browsers. if it is just
browsers in use then there are many who argue that IE is already the
majority, if you mean the majority of distinct browsers then the
majority are not javascript capable so DHTML was never going to work for
them.
To build really
maintainable and effective DHTML Apps, the compatible browser list
must be narrowed.
There are a number of practices that are known to impact on the
reliability of browser scripts, one of which is the use of invalid
mark-up. If DHTML support is going to be restricted then there really
should be a better reason for reducing it below support for all
javascript capable dynamic browsers than an unwillingness to author
structurally valid HTML.
At this time, Mozilla and IE never complain about putting code there
and I am pretty sure with enough nagging, W3C could be convinced that
it's not such a bad idea to allow script tags after the closing body
tag.
The expression "a snowball's chance in hell" springs to mind. The W3C
seem to want to increase the requirements for formal correctness in web
authoring (at least the move towards XHTML implies as much) and they
also seem to like the idea of semantic mark-up. A primary document
division of HEAD, BODY and SCRIPT, with script also allowed in many
other contexts, would not sit well with that goal.
I have not had the time, nor the need, to test multiple browsers
compatibility. Just IE 5.5sp2+ and Moz 1.3+. At least this could be
used as a back door to the body's onload event.


There is no fundamental problem with Mac OS X onload handlers in IE 5
and Safari, they work fine when I test them. Where onload handlers fail
is when a browser is used in conjunction with a
content-inserting/re-writing proxy (personal firewalls and such like)
with its settings configured to prevent onload (or sometimes onload
generated pop-ups, where the onload script errors while failing to
generate the pop-up), or on browsers like Mozilla which offer the user
options to refuse the execution of onload/onunload events.

But your invalid mark-up can be avoided by just moving the script
element to just before the closing BODY tag, when all of the elements on
the page will have been created in the DOM (if not maybe fully
configured, especially in terms of dimensions and positions/offsets).

Richard.
Jul 23 '05 #7

P: n/a
> You have edited my post here without indicating that you have done so,
moving my response to a direct statement of yours out of its original
context.
Sorry dude, my mistake.
But your invalid mark-up can be avoided by just moving the script
element to just before the closing BODY tag, when all of the elements on
the page will have been created in the DOM (if not maybe fully
configured, especially in terms of dimensions and positions/offsets).


Good suggestion.

I will try this technique. Nice thing about this technique is that the
javascript thread executed could use document.writes where if after
the closing body tag, you would have to use
document.body.innerHTML+=... (or other similar method)

To be honest, I cannot remember the exact browser that had the problem
with the onload method. It was either on my OSX box (ibook) with
Mozilla or on my win2k (dell) box with IE or Moz. The problem may
actually have been fixed but at the time it pissed me off so much that
I did bypass surgery on my pages and it's been working happily ever
since.

I realise that have been overly spoiled by working in a large but
contained corporate intranet world. Your points on building standards
based HTML is well taken.

Thanks for your time and input.

Tim
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.