Gli ultimi tutorial di sviluppo web
 

Finestra screenX e screenY Proprietà

<Window Object

Esempio

Restituire le coordinate xey della finestra rispetto allo schermo:

var myWindow = window.open("", "myWin");
myWindow.document.write("<p>This is 'myWin'");
myWindow.document.write("<br>ScreenX: " + myWindow.screenX);
myWindow.document.write("<br>ScreenY: " + myWindow.screenY + "</p>");
Prova tu stesso "

Più "Try it Yourself" esempi di seguito.


Definizione e l'utilizzo

Le proprietà screenX e Screeny restituisce i x (horizontal) e Y (vertical) coordinate della finestra rispetto allo schermo.


Supporto browser

I numeri nella tabella indicano la prima versione del browser che supporta pienamente la proprietà.

Proprietà
screenX 9.0
screenY 9.0

Tip: per IE8 e precedenti, è possibile utilizzare " window.screenLeft " e " window.screenTop ", invece (See "More Examples") .


Sintassi

window.screenX
window.screenY

Dettagli tecnici

Valore di ritorno: Un numero che rappresenta la distanza orizzontale e / o verticale della finestra rispetto allo schermo, in pixel

Esempi

Altri esempi

Esempio

Aprire una nuova finestra con una posizione specificata a sinistra e in alto, e restituire le sue coordinate:

var myWindow = window.open("", "myWin", "left=700, top=350, width=200, height=100");
myWindow.document.write("<p>This is 'myWin'");
myWindow.document.write("<br>ScreenX: " + myWindow.screenX);
myWindow.document.write("<br>ScreenY: " + myWindow.screenY + "</p>");
Prova tu stesso "

Esempio

Soluzione cross browser (using screenLeft and screenTop for IE8 and earlier) :

// Open a new window with a specified left and top position
var myWindow = window.open("", "myWin", "left=700, top=350, width=200, height=100");

/*
If the browser does not support screenX and screen Y,
use screenLeft and screenTop instead (and vice versa)
*/
var winLeft = myWindow.screenLeft ? myWindow.screenLeft : myWindow.screenX;
var winTop = myWindow.screenTop ? myWindow.screenTop : myWindow.screenY;

// Write the new window's x and y coordinates relative to the screen
myWindow.document.write("<p>This is 'myWin'");
myWindow.document.write("<br>Horizontal: " + winLeft);
myWindow.document.write("<br>Vertical: " + winTop + "</p>");
Prova tu stesso "

<Window Object