Определить ширину экрана или страницы JavaScript

Содержание
Введение
Пример
body.clientWidth: ширина страницы
Похожие статьи

Введение

Если нужно определить ширину экрана логично воспользоваться JavaScript

Пример

Создайте файл width.html Добавьте все обязательные теги и кое что ещё

width.html

<div class="p1 anchor">Device Screen Width: <span id="example"></span></div> <script> document.getElementById("example").textContent = screen.width; </script>

Banner image

Ширина документа

Часто нужно знать не ширину экрана, а ширину страницы. Её можно получить через ширину body.

body_width.html

<div class="p1 anchor">Body Width: <span id="bw"></span></div> <script> document.getElementById("bw").textContent = document.body.clientWidth; </script>

Article author: Andrei Olegovich

Похожие статьи
JavaScript
Функции
typeof(): Определить тип переменной
Массивы
Сортировка массива
Скролл вверх и вниз
Определить ширину экрана
Mocha Framework
Запросы к REST API на JS
TicTacToe
Ошибки

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: