Méthode moveTo()de Window
Objet Window
Définition et utilisation
La méthode moveTo() déplace le coin supérieur gauche d'une fenêtre vers une coordonnée spécifiée.
Syntaxe
window.moveTo(x,y)
Prise en charge des navigateurs
![]()
![]()
![]()
![]()
![]()
Tous les principaux navigateurs prennent en charge la méthode moveTo()
Remarque :Spécifiez moveTo(0.0) pour placer la fenêtre dans le coin supérieur gauche du navigateur dans Opera.
Exemple
Exemple
Déplacez la nouvelle fenêtre dans le coin supérieur gauche de l'écran :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Exemple(example.com)</title>
<script>
function openWin(){
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>Ceci est ma fenêtre</p>");
}
function moveWin(){
myWindow.moveTo(0,0);
myWindow.focus();
}
</script>
</head>
<body>
<input type="button" value="Ouvrir une fenêtre" onclick="openWin()" />
<br><br>
<input type="button" value="Déplacer la fenêtre" onclick="moveWin()" />
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Exemple(example.com)</title>
<script>
function openWin(){
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>Ceci est ma fenêtre</p>");
}
function moveWin(){
myWindow.moveTo(0,0);
myWindow.focus();
}
</script>
</head>
<body>
<input type="button" value="Ouvrir une fenêtre" onclick="openWin()" />
<br><br>
<input type="button" value="Déplacer la fenêtre" onclick="moveWin()" />
</body>
</html>
Essayez-le vous-même »
Objet Window Autres extensions