OVH Cloud OVH Cloud

Problème de position souris !

14 réponses
Avatar
[Bruno]
Bonjour à tous,

Voici un script (voir ci-dessous) qui devrais fonctionner sous FireFox
mais qui ne marche pas !

L’idée est que ce popup s’ouvre à la position de la souris !
Donc récupérer en deux variables X et Y de la position de la souris et
faire un window.open() avec c’est deux valeurs.

Pouvez-vous m’aider ?


<html>
<head>
<title>Test Popup</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function Point(x,y) { this.x = x; this.y = y; }
mouseLocation = new Point(-500,-500);

function getMouseLoc(e) {
if(!document.all){ //NS
mouseLocation.x = e.pageX + window.screenX - 85;
mouseLocation.y = e.pageY + window.screenY - 90;
} else { //IE
mouseLocation.x = event.x + window.screenLeft - 85;
mouseLocation.y = event.y + window.screenTop - 90;
}
return true;
}
//NS init:
if(document.layers){
document.captureEvents(Event.MOUSEMOVE);
document.onMouseMove = getMouseLoc;
}

function openWindowCalendar(url) {
if (document.layers) getMouseLoc; //NS
else if (document.all) getMouseLoc(); //IE
window.open(url, 'popup_calendar',
'resizable,width=170,height=180,left='+mouseLocation.x+',top=0'+mouseLocation.y)
}

//-->
</script>
</head>
<body>
<br>
<br>
Le PopUp devrait s'ouvrir la ou se trouve la souris !
<a href="JavaScript://"
onClick="openWindowCalendar('http://www.google.fr');">Tester</a>
</body>
</html>

4 réponses

1 2
Avatar
[Bruno]
Donc aprés j'ai testé ca :

<html>
<head>
<title>Test Popup</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function openWindowCalendar(url) {
ieúlse
/*@cc_on ie=true
@*/
if(ie) {
x = event.x + window.screenLeft - 85;
y = event.y + window.screenTop - 90;
window.open(url, 'popup_calendar',
'resizable,width0,height0,left='+x+',top=0'+y)
} else {
x = e.pageX + window.screenX - 85;
y = e.pageY + window.screenY - 90;
window.open(url, 'popup_calendar',
'resizable,width0,height0,left='+x+',top=0'+y)
}
}
//-->
</script>
</head>
<body>
<br>
<br>
Le PopUp devrait s'ouvrir la ou se trouve la souris !
<a href="JavaScript://"
onClick="openWindowCalendar('http://www.google.fr');">Tester</a>
</body>
</html>

et la ca ne marche pas !
Avatar
[Bruno]
...

et la ca ne marche pas !


enfin sous IE ca marche mais pas FF ni Netscape !?!...


PS : Merci pour votre compation en vers un débutant.

Avatar
O.L.
[Bruno] a émis l'idée suivante :
PS : Merci pour votre compation en vers un débutant.


Moi je compatis :)

--
Olivier Ligny
Créateur web free-lance / www.cyber-tamtam.net

Avatar
Olivier Miakinen
ieúlse
/*@cc_on ie=true
@*/


Ceci n'est à utiliser qu'en dernière extrémité, c'est-à-dire si tu n'as
pas d'autres propriétés plus pertinentes à te mettre sous la dent.

Or, ici, tu en as. Il faudrait peut-être remplacer partout les tests du
style (event.x) par (event.x !== null) ou (event.x !== undefined), mais
je n'ai pas le temps tout de suite de chercher la bonne syntaxe. En tout
cas voilà l'idée :

if(ie) {
x = event.x + window.screenLeft - 85;
y = event.y + window.screenTop - 90;
window.open(url, 'popup_calendar',
'resizable,width0,height0,left='+x+',top=0'+y)


if (event.x && window.screenLeft && event.y && window.screenTop) {
x = event.x + window.screenLeft - 85;
y = event.y + window.screenTop - 90;
window.open(url, 'popup_calendar',
'resizable,width0,height0,left='+x+',top=0'+y)

} else {
x = e.pageX + window.screenX - 85;
y = e.pageY + window.screenY - 90;
window.open(url, 'popup_calendar',
'resizable,width0,height0,left='+x+',top=0'+y)
}


} else if (e.pageX && window.screenX && e.pageY + window.screenY) {
x = e.pageX + window.screenX - 85;
y = e.pageY + window.screenY - 90;
window.open(url, 'popup_calendar',
'resizable,width0,height0,left='+x+',top=0'+y)

}


} else {
alert("Il va falloir trouver autre chose");
}


--
Olivier Miakinen
Aidez Saburi à rester près de sa famille et poursuivre ses études
en France, signez la pétition :
http://www.fcpe94.ouvaton.org/article_petition.php3?id_article=9

1 2