Bonjour
soit le code ci-dessous qui me permet de faire rebondir une fenetre sur les bords de l'écran
Dans la méthode démarrer j'ai bien un object window après mon window.open (contrôlé avec alert)
Dans la méthode deplacementSuivant j'ai mis une alert pour voir la valeur de fenetre qui vaut undefined à l'execution !?!
Comment cela se fait-il ? J'ai perdu la valeur de mon attribut récupéré auparavant avec window.open ?
Si quelqu'un pouvait m'expliquer gentillement se serait sympa car j'avoue ne pas comprendre la logique de javascript là du coup...
Merci d'avance.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" > <head> <title>PAGE PRINCIPALE</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8"> <script type="text/javascript"> function rebond() { this.x=0; this.y=0; this.w=200; this.h=200; this.dx=5; this.dy=5; this.intervalle=100; this.fenetre=null; this.minuterie=null; this.demarrer = function () { this.x = (screen.width - this.w)/2; this.y = (screen.height - this.h)/2; this.fenetre= window.open('javascript:"<h1>REBOND !</h1>"',"", "left=" + this.x + ",top="+this.y+ ", width="+this.w + ",height="+this.h+",status=yes"); this.minuterie= setInterval( this.deplacementSuivant, 100 ); } this.arreter=function() { clearInterval(this.minuterie); if(!this.fenetre.closed) this.fenetre.close(); } this.deplacementSuivant = function(){ alert("alert deplacement "+this.fenetre); if(!this.fenetre) if(this.fenetre.closed){ clearInterval(this.minuterie); return; } if((this.x+this.dx>(screen.availWidth -this.w)) || (this.x+this.dx<0)) this.dx=-this.dx; if((this.y+this.dy>(screen.availHeigth -this.h)) || (this.y+this.dy<0)) this.dy=-this.dy; this.x+=this.dx; this.y+=this.dy; this.fenetre.moveTo(this.x, this.y); this.fenetre.defaultStatus="("+this.x+","+this.y+")"; } } </script> </head> <body> <script> var my = new rebond(); my.demarrer(); delete my; </script> </body> </html>
Partager