Gli ultimi tutorial di sviluppo web
 

Finestra screenLeft e screenTop 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>ScreenLeft: " + myWindow.screenLeft);
myWindow.document.write("<br>ScreenTop: " + myWindow.screenTop + "</p>");
Prova tu stesso "

Più "Try it Yourself" esempi di seguito.


Definizione e l'utilizzo

Le proprietà screenLeft e screenTop 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à
screenLeft Non supportato
screenTop Non supportato

Note: Per Firefox, usano " window.screenX " e " window.screenY " (See "More Examples" for a cross-browser solution) .


Sintassi

window.screenLeft
window.screenTop

Dettagli tecnici

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

Esempi

Altri esempi

Esempio

Soluzione cross browser (using screenX and screenY 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