[js] meerdere document.body.onload

Pagina: 1
Acties:

  • r0bert
  • Registratie: September 2001
  • Laatst online: 11-08 16:19
't lijkt me niet zo'n moeilijke vraag, maar ik kom er gewoon niet uit. Heb al gezocht, maar kan niets vinden.

Ik wil door middel van het onload event van het body element, een aantal functies aanroepen. 1 functie lukt wel, maar om er meerdere toe te voegen wil op de een of andere vage manier niet..
code:
1
2
document.body.onload = functie1('blaat');
document.body.onload = functie2('blabla');

of
code:
1
2
document.body.onload += functie1('blaat');
document.body.onload += functie2('blabla');

werken allebij niet.. :'(

[edit]
code:
1
2
document.body.onload += alert('blaat');
document.body.onload += alert('blabla');

Geeft wel 2 alertje }:O

  • supakeen
  • Registratie: December 2000
  • Laatst online: 09-09-2025
Ik weet niks van java maar misschien kun je ze allebei op 1 regel aanroepen :?
iets van:
code:
1
document.body.onlad = functie1('blaat'), functie2('blabla');

:?

  • r0bert
  • Registratie: September 2001
  • Laatst online: 11-08 16:19
Op donderdag 27 juni 2002 12:06 schreef zmn het volgende:
Ik weet niks van java maar misschien kun je ze allebei op 1 regel aanroepen :?
iets van:
code:
1
document.body.onlad = functie1('blaat'), functie2('blabla');

:?
Goed idee, maar hij wil 't niet pa-/pikken

  • André
  • Registratie: Maart 2002
  • Laatst online: 03-09 14:12

André

Analytics dude

code:
1
2
3
4
5
6
function Init()
{
  //Blaat
}

document.body.onload = Init()

Zo?

  • Guillome
  • Registratie: Januari 2001
  • Niet online

Guillome

test

Heel simpel

<body onload='functie1(); functie2(); if (1 == 1) alert("blah");'>
of
<body onload='loadfuncties();'>

en dan tussen de <head> tags
<script>
function loadfuncties()
{
functie1();
functie2();
et. etc. etc.
}
</script>

If then else matters! - I5 12600KF, Asus Tuf GT501, Gigabyte Gaming OC 16G 5080 RTX, Asus Tuf Gaming H670 Pro, 48GB, Corsair RM850X PSU, SN850 1TB, Arctic Liquid Freezer 280, ASUS RT-AX1800U router


  • r0bert
  • Registratie: September 2001
  • Laatst online: 11-08 16:19
't zou zo via een omweg ook wel kunnen, maar ..

Wou 't liever via m'n eigen eerste methode doen, want nu moet ik binnen de init() functie met if statements gaan werken, die ik dan eerst weer via asp aan moet maken blablabla..

Dus als iemand weet hoe je ze (via scripting) achter elkaar aan kan roepen, graag.. anders moet het maar op de 'moeilijke' manier

  • Tom
  • Registratie: Juni 1999
  • Niet online

Tom

Op donderdag 27 juni 2002 12:55 schreef r0bert het volgende:
Dus als iemand weet hoe je ze (via scripting) achter elkaar aan kan roepen, graag.. anders moet het maar op de 'moeilijke' manier
dat zei iemand net:

onload="functie1(); functie2('bla');"
etc.

Verwijderd

Op donderdag 27 juni 2002 12:37 schreef Yogho het volgende:
code:
1
2
3
4
5
6
7
function Init()
{
 functie1();
 functie2('Henkie'); 
}

document.body.onload = Init()

Zo?
Zo dus..

  • Clay
  • Registratie: Oktober 1999
  • Laatst online: 22-06 13:51

Clay

cookie erbij?

Onloads loshalen dat je ze overal en nergens kan toevoegen is idd erg handig. :) Ik heb zelf onlangs dit gemaakt:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Event attacher
// ----------------------------------------------
document.events = [];
document.attachEvent = function(type, reference) {
    var evt = this.events;
    if(!evt[type]) evt[type] = [];
    evt[type][evt[type].length] = reference;

    document[type] = function(e) { 
        document.executeEvents(type, e);        
    }
}   

document.executeEvents = function(type, e) {
    for(var i in this.events[type]) {
        this.events[type][i](e);
    }   
}

window.onload = function() { document.executeEvents('onload'); }
window.onresize = function() { document.executeEvents('onresize'); }
// ----------------------------------------------


function onloader1() {
    alert('dit is onload 1')
}

function onloader2() {
    alert('dit is onload 2')
}

function showcoords() {
    window.status = event.x+' '+event.y
}

function clickedie() {
    alert(event.button)
}

document.attachEvent('onload', onloader1)
document.attachEvent('onload', onloader2)
document.attachEvent('onmousedown', clickedie)
document.attachEvent('onmousemove', showcoords)

Is erg handig :)

Instagram | Flickr | "Let my music become battle cries" - Frédéric Chopin

Pagina: 1