JS to tell if an object is viewable on the screen

 
Here is some JavaScript that has a function to tell if an object 
is viewable on the screen.
This is quite helpful if you have something on the screen you 
want to make sure the user sees,

like a an error or license agreement, etc.
 
<HTML>
<HEAD>
<SCRIPT>
function isinView(oObject)
{
    var oParent = oObject.offsetParent;
    var iOffsetTop = oObject.offsetTop;
    var iClientHeight = oParent.clientHeight;
    if (iOffsetTop > iClientHeight) {
        alert("Special Text not in view. Expand Window to put Text in View.");
    }
    else{
         alert("Special Text in View!");
    }
}
</SCRIPT>
</HEAD>
<BODY onload="window.resizeTo(430,250)" onclick="isinView(oID_1)"  SCROLL=NO>

<DIV STYLE="position:absolute;left:20px">Click anywhere in window to see if special text is in
view.</DIV>

<DIV id="oID_1" STYLE="position:absolute; left:50px;top:300px;width:280px;color:lightGreen;
font-size:large;font-weight:bold;background-color:hotPink;font-family:Arial">
            Here's some special text
</DIV>
</BODY>
</HTML>
Technorati Tags: ,

posted @ Monday, December 07, 2009 7:56 AM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 1 and 8 and type the answer here:
 

Live Comment Preview: