bonjour,

Je demande de l'aide car je tourne en rond depuis des jours ... :

J'ai �crit une fonction "PopUp" que j'appelle de 2 mani�res diff�rentes: appel "direct" et appel via une autre fonction js.

La fonction donne ce que j'attends quand je l'appelle avec la premi�re m�thode, mais elle ne fonctionne pas correctement avec la seconde.

La pop up apparait bien (donc l'appel � la fonction s'effectue bien) mais ne disparait pas au bout du timeout. (J'ai aussi men� les tests avec le m�me url pour la popup, mais m�me r�sultat):

La fonction "Ferme" n'est m�me pas appel�e, je crois la cl� du myst�re est l�.


Je joins le code si quelqu'un peut jeter un oeil averti :

La fonction "PopUp" :

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
function PopUp(url, on_off, title, width, height, positionX, positionY, timeout, debug) {
 
	// variable globale pour appel de la fermeture de la fenetre dans une autre sous-fonction
	var my_window;
 
	function Ouvre(on){
		var options	= 'toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,menubar=0';	
			if (on == true) {
				my_window = window.open(url, title, options+',top='+PosY+',left='+PosX+',width='+width+',height='+height);
				alert('Debug: ouverture de ' + my_window + ', avec url= '+ url);
			}
		}
 
	function Ferme(off){
		//alert('debug: tentative fermeture');
		if (off == true) {
			//alert('debug: demande fermeture popup');
			if (my_window.document) {
				//alert('debug: fermeture popup');
				my_window.close();
			}
		}
	}
 
	// Init et controle des parametres d'entrée
	timeout	= (timeout == 0 )? timeout = 1000 : timeout;
	var marginX	= 20;
	var marginY	= 20;
	var ScreenX = screen.availWidth;
	var ScreenY = screen.availHeight;
 
	if ((positionX != 'center') && (positionX != 'left') && (positionX != 'right')) {
		positionX = 'center' ;
	}
	if ((positionY != 'top') && (positionY != 'center') && (positionY != 'bottom')) {
		positionY = 'center' ;
	}
 
	// debug
	if (debug) { alert('X:' + positionX + ' Y:' + positionY); }
 
 
	// Calcul de la position (PosX,PosY) d'affichage de la fenetre selon les parametres user
	// methode: Xa: coin sup gauche, Xo: centre de la fenetre => on cherche Xo puis on deduit Xa (ou PosX)
	// même principe pour PosY
 
	if (positionX == 'center') {
		PosX	= Math.round((ScreenX-width)/2);
	}
 
	if (positionX == 'left') {
		PosX	= (Math.round((ScreenX/2-width)/2) > marginX )? Math.round((ScreenX/2-width)/2) : marginX ;
	}
 
	if (positionX == 'right') {
		PosX	= (Math.round(ScreenX*3/4 - width/2) < ( ScreenX - marginX - width) )? Math.round(ScreenX*3/4 - width/2 ) : ScreenX - marginX - width ;
	}
 
	if (positionY == 'top') {
		PosY	= (Math.round(ScreenY/4 - height/2) > marginY )? Math.round(ScreenY/4 - height/2) : marginY ;
	}
 
	if (positionY == 'center') {
		PosY	= Math.round((ScreenY-height)/2);
	}
 
	if (positionY == 'bottom') {
		PosY	= (Math.round(ScreenY *3/4 - height/2) < ScreenY - marginY - height )?  Math.round(ScreenY *3/4 - height/2) : ScreenY - marginY - height ;
	}
 
	// debug
	// alert('url: '+url+' Open: '+on_off+' TimeOut (ms): '+timeout);
 
	// Actions à mener
	if (on_off == 'open')	{
			Ouvre(true);
			//alert('timeout = ' + timeout);
			setTimeout(function(){Ferme(true)}, timeout); // Après un délai de 'timeout' millisecondes, on ferme la fenetre
	}
 
	if (on_off == 'close')	{
			Ferme(true);
	}
//return false;
}
La premi�re m�thode d'appel (appel direct), qui fonctionne :

Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
$popup = "PopUp('$url_img', 'open', 'test', '200', '150', 'right', 'top', '".POPUP_TIMEOUT."', false); return false;";
 
echo '<td>'.'<a href="javascript:void(0)" onclick="'.$popup.'" onmouseout="nd();" onmouseover="return overlib(\'<img src='.$imgtoshow.'>\', CAPCOLOR, \'#000000\', CAPTION, \''.$text.'\')">'.$value.'</a>'.'</td>';

La seconde m�thode d'appel , qui ne fonctionne pas :

d'abord, j'attache la fonction PleaseWait � l'�venement onclick des balises <a>, et �a, �a fonctionne bien :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
var id_array = getElementsByRegExpId(/^pleasewait.+/, document.body , 'a');
		var timeout = 1000;
		// alert('liste des Pls Wait: ' + id_array);
		for (i = 0 ; i < id_array.length ; i++) {
			if (document.getElementById(id_array[i])) {
			   leLien = document.getElementById(id_array[i]);
			   leLien.onclick = function() {
				   PleaseWait(timeout);
			   }
		   }
	   }
Puis la fonction "PleaseWait" , plus basique tu meurs :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
function PleaseWait(timeout) {
	PopUp('https://www.xxxxx.fr/ftp/local/pop_wait.html', 'open', 'test', '200', '200', 'left', 'center', timeout, false);
	//return false;
}