473,395 Members | 1,441 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,395 software developers and data experts.

Any alternative to onload?

Is there anyway to do something exactly like onload, but without the word
onload?

I am trying to write inline js without onload, so I don't know how to
trigger/start the script.
Jul 23 '05 #1
9 22227
> Is there anyway to do something exactly like onload, but without the word
onload?

I am trying to write inline js without onload, so I don't know how to
trigger/start the script.


By the way, onmouseover, onblur are all ok. But they require the mouse to
move to the object. Is there a way to make the script run 100%? BODY tag is
not allowed either, so I have to either use a huge table for onmouseover. Is
there any event like onmousemove?
Jul 23 '05 #2
nntp wrote:
Is there anyway to do something exactly like onload, but without the word
onload?


You can include the script in the head of your document and kick it off
without a "function" statement - a trivial example below:

<html>
<head><title> Auto-alert </title>
<script type="text/javascript">
alert('Hi from the head')
</script>
</head>
<body onload="alert('Hi from onload');">
Here is the body
</body>
</html>

Of course, instead of popping up an alert, you can call a function or
whatever. Just remember that the script will execute when the browser
reaches it and *will not* wait for the rest of the page to load.

In the example, you should have a blank page until you dismiss the
first alert, then the rest of the page is loaded, then the 'onload'
alert is triggered. So if you are going to manipulate elements, put
the script right at the bottom. Note also that images will likely not
be loaded when your script loads and the user may have already clicked
something before it executes, so it doesn't because the browser has
already headed off to a new location...

Still want to do it? Onload was created for a purpose.

Cheers, Rob.
Jul 23 '05 #3
nntp wrote:
Is there anyway to do something exactly like onload, but without the word
onload?

I am trying to write inline js without onload, so I don't know how to
trigger/start the script.

By the way, onmouseover, onblur are all ok. But they require the mouse to
move to the object. Is there a way to make the script run 100%? BODY tag is
not allowed either, so I have to either use a huge table for onmouseover. Is
there any event like onmousemove?


I think it best you explain what you are trying to achieve. How can
you have a table if you don't have a body? You can execute scripts by
just putting commands inside <script> tags, a trivial example is below.

Note that the script executes when the browser reaches it, not when it
has actually rendered the page. Onload was created to run *after* the
page is fully loaded. In the example, the alert in the header runs
before the <body> tag is reached (or the </head> tag for that matter).

The alert in the body will likely run before the page is rendered too,
certainly before images have finished loading, and finally, after the
page is loaded and rendered, the onload will run.

Since you don't want to have a body tag, I presume you are writing the
entire page using JavaScript, which seems quite pointless to me, but if
that's what you want to do have a search for the thread on "writing
slabs of HTML", it should be useful. There is a second example below.

Cheers, Fred.
*Example I:*

<html><head><title> Auto Run </title>

<script type="text/javascript">
doStuff();

function doStuff() {
alert('doStuff\(\) says hello');
}
</script>
</head>
<body onload="alert('Hi from onload');"
style="background-color: #eeeeff;">
<h2>Here is the body</h2>
<script type="text/javascript">
alert('Here I am in the body');
</script>
</body>
</html>

*Example II:*

<html><head><title> Auto Run </title>
</head>
<script type="text/javascript">

var a = [
'<body><h2>here is some text<\/h2>',
'<form action="">',
'<input type="button" value="Click me" ',
'onclick="alert(\'Hi guys\');">',
'<\/form>',
'<\/body>',
];
document.write(a.join(""));
document.close();
</script>
</html>

Jul 23 '05 #4
nntp wrote:
Is there anyway to do something exactly like onload, but without the word
onload?

I am trying to write inline js without onload, so I don't know how to
trigger/start the script.

By the way, onmouseover, onblur are all ok. But they require the mouse to
move to the object. Is there a way to make the script run 100%? BODY tag is
not allowed either, so I have to either use a huge table for onmouseover. Is
there any event like onmousemove?


I think it best you explain what you are trying to achieve. How can
you have a table if you don't have a body? You can execute scripts by
just putting commands inside <script> tags, a trivial example is below.

Note that the script executes when the browser reaches it, not when it
has actually rendered the page. Onload was created to run *after* the
page is fully loaded. In the example, the alert in the header runs
before the <body> tag is reached (or the </head> tag for that matter).

The alert in the body will likely run before the page is rendered too,
certainly before images have finished loading, and finally, after the
page is loaded and rendered, the onload will run.

Since you don't want to have a body tag, I presume you are writing the
entire page using JavaScript, which seems quite pointless to me, but if
that's what you want to do have a search for the thread on "writing
slabs of HTML", it should be useful. There is a second example below.

Cheers, Fred.
*Example I:*

<html><head><title> Auto Run </title>

<script type="text/javascript">
doStuff();

function doStuff() {
alert('doStuff\(\) says hello');
}
</script>
</head>
<body onload="alert('Hi from onload');"
style="background-color: #eeeeff;">
<h2>Here is the body</h2>
<script type="text/javascript">
alert('Here I am in the body');
</script>
</body>
</html>

*Example II:*

<html><head><title> Auto Run </title>
</head>
<script type="text/javascript">

var a = [
'<body><h2>here is some text<\/h2>',
'<form action="">',
'<input type="button" value="Click me" ',
'onclick="alert(\'Hi guys\');">',
'<\/form>',
'<\/body>',
];
document.write(a.join(""));
document.close();
</script>
</html>

Jul 23 '05 #5
*nntp* wrote:
Is there anyway to do something exactly like onload, but without the word
onload?

I am trying to write inline js without onload, so I don't know how to
trigger/start the script.


Sorry, the problem you describe is not very clear. I suspect you mean
that you can't add the onload attribute to your body tag (for various
reasons), but nevertheless require an onload ability? In which case the
script: window.onload = MyFunction; would probably do the job for you.

Then again you mention 'write inline script' and this could imply the
use of document.write() - if so you likely won't want to be executing
that after the document has been loaded.

Anyhow, not knowing what you really want, here's a snippet of script
that attempts to execute function MyFunction() after the document has
loaded and tries not to use "onload" unless it's the only available
method of invoking functions after the document has loaded:
if (window.attachEvent) {
window.attachEvent('onload', MyFunction);
}
else if (window.addEventListener) {
window.addEventListener("load", MyFunction, false);
}
else {
window.onload = MyFunction;
}

--
Andrew Urquhart
- FAQ: http://www.jibbering.com/faq/
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: http://andrewu.co.uk/contact/
Jul 23 '05 #6
<body> tag is not allowed
<table> is ok

onload is not allowed
onmouseover is ok.

I got it myself
I used <div> + onmouseover
it is almost equal to body+onload, except when the mouse is not on the
screen.

Thanks.
Jul 23 '05 #7
Lee
nntp said:

<body> tag is not allowed
<table> is ok

onload is not allowed
onmouseover is ok.


When you're asking for a way to work around some limitation
(eg, no body tag), it's a really good idea to explain why you
face that limitation. If you don't, people are going to waste
time asking, anyway, and you probably won't get as much help.

I've had some experiences in which the "page" I was writing
was actually going to be incorporated into a standard <body>
by server-side code, so that's what I'm picturing here.

Jul 23 '05 #8
Lee <RE**************@cox.net> wrote in news:cl*********@drn.newsguy.com:
When you're asking for a way to work around some limitation
(eg, no body tag), it's a really good idea to explain why you
face that limitation. If you don't, people are going to waste
time asking, anyway, and you probably won't get as much help.


And some people will jump to the conclusion that you're a student asking
other people to do his homework for him.
Jul 23 '05 #9
nntp wrote:
<body> tag is not allowed
<table> is ok

onload is not allowed
onmouseover is ok.

I got it myself
I used <div> + onmouseover
it is almost equal to body+onload, except when the mouse is not on the
screen.


Thats not even close to true. The body/windows onload will only fire
once until the page is reloaded. onmouseover will fire repeatedly if the
mouse is moved in/out of the div. That makes a *huge* difference.

But the whole question almost sounds like homework.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #10

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

Similar topics

1
by: Peter Cartwright | last post by:
Is there a functional equivalent to <body onload="function call" in the main script. Can one do something like document.body.onload=function call?
2
by: llaxman | last post by:
Hello everyone, I was wondering if anyone can help me? I am having some problems wit the <noscript> tag. I actually use it to block banner advertisements from being displaye in my website. I...
2
by: Rich | last post by:
Is there any way I can check to see if a document is loaded into the iframe before I call onLoad (sort of an afterLoad). I'm loading up a page into an iframe. But because we use four servers...
2
by: Jarson | last post by:
My webserver hosts some on-line reports with live data. I have put an html meta tag to force the client to refresh every 10 minutes so my clients will always show the latest data .. <meta...
5
by: joe | last post by:
Hi. Is there a way with Javascript to use a generic image if the one I want is not found? I'd appreciate if someone can post a code sample, or poit me to one. Thanks in advance.
3
by: Vik Rubenfeld | last post by:
I'm working on integrating the a javascript wysiwyg editor (Xinha) with my blog software (ExpressionEngine, aka EE). EE has extensions now so it's easy to get the Xinha header code into the head...
7
by: Spartanicus | last post by:
Afaik the use of a <noscriptelement is frowned upon nowadays. For a JS random image changer I tried to use a replacement by having the script change the HTML src attribute value of an img element....
15
by: Aaron Gray | last post by:
I have two tables in <spansI want side by side, okay in IE but in Mozilla I need to use "display: -moz-inline-box;" this does not work in Opera which requires "display: inline-block". Is there...
2
by: Roger | last post by:
I have an application with an input form that sometimes has a hundred or so check boxes organized into groups of about 10 choices. The boxes are difficult to check because the target is small and...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.