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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:22:29+00:00 2026-05-28T15:22:29+00:00

I am trying to write an JavaScript to extract the pictures in the html

  • 0

I am trying to write an JavaScript to extract the pictures in the html whose width and height are higher than a specified value. I use the DOM to extract the pictures. Here’s the problem:

The pages that I want to extract has actually a JavaScript called “checkimagesize”. Each will call an onload function like:

<img src="./01_files/mobile01-cdbd8.jpg" id="http://attach.mobile01.com/attach/201112/mobile01-cdbd8.jpg" onload="checkimagesize(this.id,this.width,this.height)" />

After each calls the “checkimagesize”, I use DOM to extract the pictures. The width and height are all zero. (The pictures are reized by the onload function)

Does anyone know how to get the actual width and height of these pictures after it called the resize function?

Thank you very much.

function checkimagesize(image, wi, hi)
{
    var wo = wi + 40;
    var ho = hi + 40;
    var resize = false;
    var imax = 640;
    if (wi > imax) {
        rating = wi / imax;
        wi = Math.ceil(wi / rating);
        hi = Math.ceil(hi / rating);
        resize = true;
    }

    if (resize) {
        reimg = document.getElementById(image);
        reimg.width = wi;
        reimg.height = hi;
        reimg.onclick = function () {window.open(image, '', 'resizable=yes,status=yes,scrollbars=yes,width='+wo+',height='+ho);};
        reimg.style.cursor = 'pointer';
    }
}

my code:

listPics = document.images;
listPics[i].width 
listPics[i].height
  • 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-05-28T15:22:30+00:00Added an answer on May 28, 2026 at 3:22 pm

    You are probably trying to access the image properties before they have finished loading. Try executing your code after the window’s load event (when all page elements have finished loading):

    window.onload = function () {
        for (var i = 0; i < document.images.length; i++) {
            var img = document.images[i];  
            console.log("image size: " + img.width + "×" + img.height);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a javascript function that adds some DOM nodes to the
I am trying to write DOM viewer on JavaScript. How I can get all
Imagine an HTML form with multiple submit buttons, Im trying to write javascript function
I am trying to write a javascript function that calls an Dictionary value and
I am trying to write my own Javascript Framework something like jQuery. I use
I am trying to write a JavaScript function to get the current browser width.
I am trying to write a javascript code that would change the value of
I'm trying to write a Javascript regex that matches words with less than 3
I'm trying to write an html/javascript set (to be interpreted in PHP) that allows
I'm trying to write a code to extract some form data from a HTML

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.