- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is cross-browser window resize events in JavaScript?
For window resize event in JavaScript, use addEventListener(). The following code will give you the size of the current window −
Example
<!DOCTYPE html> <html> <head> <style> div { margin-top: 10px; padding: 10px; background-color: #1E9E5D; width: 50%; } span { font-size: 50px; } </style> <script> window.addEventListener('resize', display); function display() { document.querySelector('.width').innerText = document.documentElement.clientWidth; document.querySelector('.height').innerText = document.documentElement.clientHeight; } display(); </script> </head> <div> <span>Width= <span class="width"></span></span><br /> <span>Height= <span class="height"></span></span> </div> </body> </html>
Advertisements