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

  • Home
  • SEARCH
  • 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 6972383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:57:39+00:00 2026-05-27T16:57:39+00:00

Test if the image I am about to grab using code is visible to

  • 0

Test if the image I am about to grab using code is visible to the user or not

Limitations:

  1. Plain javascript – please do not suggest jQuery or other framework

  2. I am only interested in display:none and visibility:hidden but opacity and such is of course welcome

Code: below (taken from here) does not work in my DEMO

Question: Can you help making either work or suggest a better script?

Version A

function isVisible(obj){
  if (obj == document) return true;
  if (!obj) return false;
  if (!obj.parentNode) return false;
  if (obj.style) {
    if (obj.style.display == 'none' || obj.style.visibility == 'hidden') return false;
  }
  else if (window.getComputedStyle) { // MY BAD - I PUT THE INCORRECT ELSE HERE
    var style = window.getComputedStyle(obj, "");
    if (style.display == 'none' || style.visibility == 'hidden') return false;
  }
  else if (obj.currentStyle) {
    var style = obj.currentStyle;
    if (style['display'] == 'none' || style['visibility'] == 'hidden') return false;
  }
  return isVisible(obj.parentNode);
}

Version B

function isVisible1(obj) {
  var cnode = obj;
  try {
    while(cnode) {
      if (cnode.nodeName) {
        if (cnode.nodeName.toLowerCase()=="body") {
          return true;
        }
      }
      if (cnode.style.display=="none" || cnode.style.visibility=="hidden") {
        return false;
      }
      cnode = cnode.parentNode;
    }
    return true;
  }
  catch(ex) {return false;}
}
  • 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-27T16:57:40+00:00Added an answer on May 27, 2026 at 4:57 pm

    Try taking the computed style conditionals outside the else of the style check. We want to check both the inline styles and the computed styles (from stylesheets.)

    Changing:

    else if (window.getComputedStyle) {
    

    To:

    if (window.getComputedStyle) {
    

    Forked fiddle: http://jsfiddle.net/MXgbh/1/

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

Sidebar

Related Questions

I have a rootfs boot image that I want to test by mounting on
I am trying to test if the uploaded file is the image type I
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
When my browser renders the following test case, there's a gap below the image.
Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const
I have a need to take an image of a series of glass test
An image says a thousand words, so what about two? I have this map
I am trying to quickly process large images (about 2000x2000). I am using a
I have a simple gallery style link setup using image swap on hover that
I'm trying to write a simple test that creates an image element, checks the

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.