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

The Archive Base Latest Questions

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

Using the following code, I get the size of an image: function getFileSize(img) {

  • 0

Using the following code, I get the size of an image:

function getFileSize(img) {
    GM_xmlhttpRequest({
        url: img.src,
        method: "HEAD",
        onload: function(response) {
            response.responseHeaders.match(/Content-Length: (\d+)/);
            size = RegExp.$1;
            if (size > maxS)
                // If size > max. allowed size
                markImage(img);
            else if (img.height > maxH)
                    // If img.height > max. allowed height
                markImage(img);
        }
    }); 
}

As you can see, the function above calls markImage:

function markImage(img) {
    img.style.border = "7px solid #990099";
    showDialog(); // This function shows a dialog
}

So I want to change the style of those images matching certain conditions.

If an image matches the conditions on getFileSize, the dialog which is called on markImage is correctly shown. However, style is not always changed.

As far as I have been able to see, the script works perfectly when size > maxS, but it doesn’t always work when img.height > maxH. Actually, if img.height > maxH, the script works if I refresh the website but it doesn’t at the first try.

On the one hand, considering the fact that markImage is called onload, this doesn’t seem to be an issue related to synchronization. In addition, the dialog is correctly shown when it has to be shown. On the other hand, I also tried to change the style by using setAttribute but it makes no difference. So I have no idea why is this “randomly” failing.

Thanks in advance for your help.

  • 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-04T05:28:43+00:00Added an answer on June 4, 2026 at 5:28 am

    Okay, if showDialog(); always fires correctly, then that rules out image loading and rendering delays.

    Some other things that could be causing the glitch:

    1. Some other CSS is overriding the CSS in markImage(). Change the code to:

      img.style.setProperty ("border", "7px solid #990099", "important");
      
    2. The page has JS that modifies or reloads the target image… Intercept, block, or cleanup after such JS as appropriate.

    If showDialog(); does not always fire correctly, that’s a different ballgame, but you indicated that this was not the case.

    If something else is going on, we can’t tell without seeing the target page and maybe the whole GM script. Link to those.

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

Sidebar

Related Questions

I am using following code to get current latitude and longitude. But none of
I'm using the following code to get an array with all sub directories from
I am using the following code to get make an IMAP connection. I am
I am using the following code to get an XML data from a website
We are using the following code to get the groups of an active directory
I'm using the following code to get response from a requested page using php
I'm currently using the following PHP code: // Get all subordinates $subords = array();
Using following code I try to get updated list of checkbuttons' corresponding text values,
With the following code I get all the pages I admin on Facebook using
I am using following PHP code for trigger creation but always get error, please

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.