[JS]Global variable na functie nog steeds undefined

Pagina: 1
Acties:

  • MaDDoG
  • Registratie: Maart 2000
  • Laatst online: 24-11-2025

MaDDoG

De brakste schakel

Topicstarter
Zoals ik al zei. Ik roep dus een global var aan in een functie, er van uitgaande dat daar dan ook mee gerekend wordt. Maar mijn script denkt daar heel anders over. En vind ze nog steeds undefined. Zo wordt het lastig om de height van reSizeToImage() te gebruiken voor mijn volgende functie. (namelijk kijken of dat niet hoger dan de resolutie is en dus een kleiner schermpje met scrollbar maken.) Het is voor een IE only intranet. Dus ik heb geen idee of het ook voor netscape werkt....of mozilla.....of opera
Hier is de code, 't is dus een pop-up script voor plaatjes:

JavaScript:
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
PositionX = 50;
PositionY = 50;


var optIE='scrollbars=auto,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle){
    imgWin=window.open('about:blank','',optIE);


    with (imgWin.document){
        writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
        writeln('<script>');

        writeln('var height;');
        writeln('var width;');
        
        writeln('function reSizeToImage(){');
            writeln('width=150-(document.body.clientWidth-document.images[0].width);');
            writeln('height=150-(document.body.clientHeight-document.images[0].height);');
            writeln('window.resizeTo(width,height);}');
        
        writeln('document.write(height);');
        writeln('document.write(width);');
        
        writeln('function doTitle(){');
            writeln('document.title="'+imageTitle+'";}');


        writeln('</script>');
        writeln('</head><body bgcolor=ffffff scroll="auto" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
    
        writeln('[img]'+imageURL+'[/img]</body></html>');
    close();    
    }
}


JavaScript:
1
2
<a href="javascript:popImage('images/doelPlaatje.gif','Titel')" />
[img]"images/thumbnail.gif"[/img]</a>

[ Voor 16% gewijzigd door MaDDoG op 14-08-2003 19:19 ]

"Computer games don't affect kids. I mean if Pacman affected us as kids,
we'd all run around in a darkened room munching pills and listening
to repetitive music."


  • crisp
  • Registratie: Februari 2000
  • Laatst online: 14:11

crisp

Devver

Pixelated

js vind dit niet zo leuk:
JavaScript:
1
writeln('</script>');


probeer het zo eens:
JavaScript:
1
writeln('<\/script>');


of zelfs zo:
JavaScript:
1
writeln('<\/scr'+'ipt>');

Intentionally left blank


  • MaDDoG
  • Registratie: Maart 2000
  • Laatst online: 24-11-2025

MaDDoG

De brakste schakel

Topicstarter
crisp schreef op 14 August 2003 @ 19:06:
js vind dit niet zo leuk:
JavaScript:
1
writeln('</script>');
Aangepast, maar geen verschil. Heb gekozen voor:
JavaScript:
1
2
3
writeln('<\scr'+'ipt>');

writeln('<\/scr'+'ipt>');

[ Voor 49% gewijzigd door MaDDoG op 14-08-2003 19:20 ]

"Computer games don't affect kids. I mean if Pacman affected us as kids,
we'd all run around in a darkened room munching pills and listening
to repetitive music."


  • crisp
  • Registratie: Februari 2000
  • Laatst online: 14:11

crisp

Devver

Pixelated

deze snap ik ook niet helemaal:
JavaScript:
1
2
writeln('document.write(height);');
writeln('document.write(width);');

wat is daar de bedoeling van?
Deze regels worden in elk geval al uitgevoerd voordat de onload getriggered wordt (tijdens het parsen al), dus krijg je 2x undefined tussen je functies in.

[ Voor 32% gewijzigd door crisp op 15-08-2003 02:43 ]

Intentionally left blank


  • MaDDoG
  • Registratie: Maart 2000
  • Laatst online: 24-11-2025

MaDDoG

De brakste schakel

Topicstarter
Ik dacht, laat ik mijn oplossing ook maar ff posten. Misschien heeft iemand dan ooit nog iets aan deze thread. Ik heb de twee acties in twee functies gestopt ipv in een proberen alles te doen.
JavaScript:
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
PositionX = 50;
PositionY = 50;


var optIE='scrollbars=auto,width=150,height=100,left='+PositionX+',top='+PositionY;

function popImage(imageURL,imageTitle){
    imgWin=window.open('about:blank','',optIE);


    with (imgWin.document){
        writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
        writeln('<\scr'+'ipt>');

        writeln('var height;');
        writeln('var width;');
        
        writeln('function reSizeToImage(){');
            writeln('width=150-(document.body.clientWidth-document.images[0].width);');
            writeln('height=115-(document.body.clientHeight-document.images[0].height);');
            writeln('window.resizeTo(width,height);}');

        writeln('function reSizeToScreen(){');
            writeln('if (height+100>=screen.height){');
            writeln('window.resizeTo(width+20,screen.height-150);}');
            writeln('else{}}');

    
        
        writeln('function doTitle(){');
            writeln('document.title="'+imageTitle+'";}');


        writeln('<\/scr'+'ipt>');
        writeln('</head><body bgcolor=ffffff scroll="auto" onload="reSizeToImage();reSizeToScreen();doTitle();self.focus()" onblur="self.close()">');
    
        writeln('[img]'+imageURL+'[/img]</body></html>');
    close();    


HTML:
1
<a href="javascript:popImage('images/Plaatje.gif','Mooi Plaatje')" />[img]"images/Thumbnail.gif"[/img]</a>

"Computer games don't affect kids. I mean if Pacman affected us as kids,
we'd all run around in a darkened room munching pills and listening
to repetitive music."