/    Sign up×
Community /Pin to ProfileBookmark

change onload event using javascript?

hello, how to change onload event <body onload=”do this”> to <body onload=”do that”> using javascript?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@CharlesJul 14.2003 — [font=monospace]<script type="text/javascript">

onload = function () {alert()}

</script>[/font]
Copy linkTweet thisAlerts:
@roleauthorJul 15.2003 — not work in this script

function changeMainPage(url) {

parent.main_page.location = url;

parent.main_page.onload = function() {alert('test')}

}
Copy linkTweet thisAlerts:
@MadCommandoJul 15.2003 — I don't think you could use "parent.main_page.onload" I think it would have to be in the page loaded, but I'm just taking a stab in the dark here.
Copy linkTweet thisAlerts:
@CharlesJul 15.2003 — [font=georgia]1) You cannot set another page's "onload" handler before it loads.

2) If you set another page's "onload" handler after it loads then the handler will not be called.

3) JavaScript has as a security feature the limitation that y ou cannot mess with other people's documents.[/font]
Copy linkTweet thisAlerts:
@roleauthorJul 15.2003 — upss.. so there is no way i can get the script work :rolleyes:

and why this script not work?

<head>

<script type="text/javascript">

<!--

onload = function() {do something}

// -->

</script>

</head>

<body onload="do something else">

i want first it "do something" and then "do something else"
Copy linkTweet thisAlerts:
@CharlesJul 15.2003 — [i]Originally posted by role [/i]

[B]why this script not work?[/B][/QUOTE]
[font=georgia]For the same reason that given:

[font=monospace]foo = 'fee';

foo = 'fie';[/font]

foo equals 'fie' and not 'feefie'. Try

[font=monospace]onload = function () {doSomething(); doSomethingElse()}[/font]

[i]or[/i]

[font=monospace]<body onload="doSomething(); doSomethingElse()">[/font][/font]
Copy linkTweet thisAlerts:
@roleauthorJul 15.2003 — onload = function () {doSomething(); doSomethingElse()} [/QUOTE]

it's work, but i want the <script> called doSomething()

and the <body> tag called doSomethingElse()

am i asked to much?? :p
×

Success!

Help @role spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...