How to detect Height within a DIV?

Discussion in 'JavaScript' started by Hipto, Feb 4, 2010.

  1. #1
    Hey guys, can someone show me how to detect height within a DIV tag, and redirect? For example if the height is 0, redirect to some other specified site

    I've read this but still no idea how to implement to redirect http://www.sitepoint.com/forums/showthread.php?t=394508

    I'll be paying $10 for thos who get it working
     
    Last edited: Feb 4, 2010
    Hipto, Feb 4, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    I think this example will help you:

    
    <html>
    
    <head>
      <title>Redirect</title>
    </head>
    
    <body>
    
    <div id="test">Hello World!</div>
    
    </body>
    
    <script type="text/javascript">
        if(document.getElementById("test").offsetHeight==0){
          location.href = "http://rubensargsyan.com/";
        }
    </script>
    
    </html>
    
    Code (markup):
     
    s_ruben, Feb 4, 2010 IP
  3. Hipto

    Hipto Peon

    Messages:
    939
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks alot. But can you give me a full example? Live if the DIV concerned are as follows

    <DIV ID=check>content</DIV>
    Would this work
    <script type="text/javascript">
    if(document.getElementById("check").offsetHeight==0){
    location.href = "http://rubensargsyan.com/";
    }
    </script>
     
    Hipto, Feb 5, 2010 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    Yes, it has to work!!!

    <DIV ID=check>content</DIV>

    <script type="text/javascript">
    if(document.getElementById("check").offsetHeight==0){
    location.href = "http://rubensargsyan.com/";
    }
    </script>

    If the div content is empty it will redirect.
     
    s_ruben, Feb 5, 2010 IP
  5. Hipto

    Hipto Peon

    Messages:
    939
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks than how should put "less than"
    like less than 10 px etc
     
    Hipto, Feb 5, 2010 IP
  6. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #6
    <DIV ID=check>content</DIV>

    <script type="text/javascript">
    if(document.getElementById("check").offsetHeight<10){
    location.href = "http://rubensargsyan.com/";
    }
    </script>
     
    s_ruben, Feb 5, 2010 IP