473,382 Members | 1,252 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,382 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 22222
> 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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...

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.