Quantcast
Channel: HTML element – Random Technical Thoughts
Viewing all articles
Browse latest Browse all 8

JS to tell if an object is viewable on the screen

$
0
0
 
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: ,


Viewing all articles
Browse latest Browse all 8