Thuộc tính window.screenLeft trả về tọa độ ngang của cửa sổ so với màn hình. Không hỗ trợ Firefox (dùng screenX thay thế).
Cú pháp
window.screenLeft
Ví dụ
<!DOCTYPE html>
<html>
<style>
body { color: #000; height: 100vh; background-color: #8BC6EC; background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%); text-align: center; }
.btn { background: #db133a; border: none; height: 2rem; border-radius: 2px; width: 40%; display: block; color: #fff; outline: none; cursor: pointer; margin: 1rem auto; }
.show { font-size: 1.2rem; }
</style>
<body>
<h1>Demo window.screenLeft (legacy)</h1>
<button onclick="showScreenLeft()" class="btn">Xem screenLeft</button>
<div class="show"></div>
<script>
function showScreenLeft() {
var val = window.screenLeft !== undefined ? window.screenLeft : 'Không hỗ trợ (Firefox)';
document.querySelector('.show').innerHTML = 'screenLeft: ' + val + 'px';
}
</script>
</body>
</html>
Kết quả
Chrome/Edge/Safari: hiển thị pixel. Firefox: "Không hỗ trợ".
Khuyến nghị: Dùng window.screenX cho cross-browser.