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 8390577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:01:46+00:00 2026-06-09T19:01:46+00:00

I have really strange problem. I’m trying to get width and height of an

  • 0

I have really strange problem. I’m trying to get width and height of an image using following way:

  1. Create a image tag and add .src to it.
  2. add this image tag to document.body.
  3. making this image tag visible (display:inline).
  4. getting .offsetWidth and .offsetHeight of element.
  5. hidding image tag(display:none);

all this is done using JS and it all work really well on my localhost, but when I uploaded a site to my client hosting provider I was amazed. offsetWidth and .offsetHeight was 0 in step 4. Why do that happen? I think that I need some kind of “flush” after step 3 before step 4, but I’m not exactly sure. Any suggestions ? Thank you.

  • 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-09T19:01:48+00:00Added an answer on June 9, 2026 at 7:01 pm

    You have to wait for the image to actually load over the network. You don’t need to add the thing to the DOM either:

    var img = new Image();
    img.onload = function() {
      handleImageSize(this.width, this.height);
    };
    img.src = "http://whatever.com/your/img.jpg";
    

    Here, “handleImageSize” would be a function you write to do whatever it is you need to do with the image dimensions.

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

Sidebar

Related Questions

I have a really strange problem, following attribute of a jsp tag <custom:tag onclick=addBid('<%=
I have a really strange problem. I'm using jQuery 1.7.1 and UI 1.8.17 for
I have a really strange problem I've been trying to work around for a
Hi everyone I have a really strange problem. I create a new subclass of
We have a really strange problem in xpages regarding dates, the Notesdocument we have
I have a really strange problem with SQL Server 2008. We have an e-commerce
I have a really strange problem and I'm completely puzzled. I have a piece
I'm having a really strange problem. I have 2 virtual machines running ubuntu 11.4
I've come across a really strange problem. I have written a simple Deck class
I am having some strange problem and its really frustating me. I have a

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.