Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:41:42+00:00 2026-06-04T01:41:42+00:00

How can I detect when a user resizes the browser window? I’m looking for

  • 0

How can I detect when a user resizes the browser window?

I’m looking for a script that does somenthing when user resizes the window or when the window’s width is less than, for example, 900px.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:41:43+00:00Added an answer on June 4, 2026 at 1:41 am

    Meh, You can use jQuery, but…

    You can subscribe to the window resize event like this:

    $(window).on("resize", function(event){
      console.log( $(this).width() );
    });
    

    Just be careful with this, since a if-statement that executes code when the width is less than n would execute that code a ridiculous number of times while you resize a window that meets those conditions. Better to set some flags or add classes to the document, and make those part of your condition as well.

    CSS Media Queries is Where It’s At!

    However, what you’re asking sounds like it would most appropriately be solved with CSS Media Queries. For instance, if we wanted to change the body background color when the window is less than 900px:

    @media screen and (max-width: 900px) {
      body {
        background: #ccc;
      }
    }
    

    There’s even a great polyfill for older version of IE: https://github.com/scottjehl/Respond

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way that I can detect browser type on routing and use
I want to have a 404 page that can detect if a user has
Is there a php or javascript code that can detect the current user's page
Is there a code snippet that can detect the current user's page and then
I'd like to get a script that can grab the user's user agent and
I want to develop an ASP.NET application that can detect the user logged on
I want to develop an Java application that can detect the user logged on
I want to develop an Java application that can detect the user logged on
In GTK (or pygtk or gtkmm...) How can I detect that an application window
Is there a way ActionScript 3 can detect the user's screen resolution?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.