Retourner ' la page d'accueil de TJSRetourner ' la page d'accueil de TJS

Script winpos : Création de la fonction getWinPos()

Création de la fonction getWinPos() qui retourne la position de la fenêtre en cours
Partie I : Les bases de JavaScript
Edition 1 | Chapitre 10 : L'objet window / Page 142
Edition 2 | Chapitre 10 : L'objet window / Page 157
Edition 3 | Chapitre 10 : L'objet window / Page 157

Exécution du script

Emulation de la console

Code source

<html><head>    <title>Déterminer la position de la fenêtre</title></head><body>    <h1 id="monH1"></h1>    <script type="text/javascript">        function getWinPos() {            var pos={x:0, y:0};            if (window.screenLeft) pos.x=window.screenLeft;             if (window.screenTop)  pos.y=window.screenTop;             if (window.screenX)    pos.x=window.screenX;             if (window.screenY)    pos.y=window.screenY;             if (window.posX)       pos.x=window.posX;             if (window.posY)       pos.y=window.posY;                         return pos;        }        var winPos=getWinPos();        console.log(winPos);        document.getElementById("monH1").innerHTML="Fenêtre en position ("+winPos.x+", "+winPos.y+")";    </script></body></html>

Troisième édition Tout JavaScript chez Dunod

Tout JavaScript le livre chez DunodEn savoir plus
Sortie le 4 janvier 2023

Version papier 29€90
Format électronique 22€99.

Commandez en ligne

Chercher une fonction, un objet, ...

Le graph des objets JavaScript



Chargement
en cours...
Le 11/05/2024 20:24:57 sur php 7 en 42.78 ms