|
These are just a few simple javascript functions I've thrown together to work
in both IE and Firefox that perform some simple functionality isn't quite as
simple as may be first thought. Javascript to test if an element is visible to a user.
var IE = document.all?true:false;
function isHidden( e, v )
{
if( typeof( v ) == 'undefined' ) { v = false; }
var style;
if( IE ) { style = e.currentStyle; } else { style = document.defaultView.getComputedStyle( e, null ); }
if( style.visibility == 'visible' && style.display != 'none' ) { return isHidden( e.parentNode, true ); }
if( v && ( style.display == 'none' || e.type == 'hidden' ) ) { return true; }
else if( style.visibility == 'hidden' || style.display == 'none' || e.type == 'hidden' ) { return true; }
if( e.nodeName == 'BODY' ) { return false; }
return isHidden( e.parentNode, v );
}
Keep track of the current mouse position:
var IE = document.all?true:false
var mouseX = 0;
var mouseY = 0;
function getMouseXY(e)
{
if( document.getElementsByTagName('body').length == 0 ) { return; }
if (!e) e = window.event;
if (e)
{
var scrollLeft = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
var scrollTop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
mouseX = IE ? (e.clientX + scrollLeft) : e.pageX;
mouseY = IE ? (e.clientY + scrollTop) : e.pageY;
}
}
document.onmousemove = getMouseXY;
TEXTAREA doesn't have a maxlenth, using this in onkeypress and onbeforepaste
will have similar results as maxlength
var IE = document.all?true:false;
function checkLength( e, item, maxlength ) {
if(!e) e = window.event; // firefox doesn't set the event. annoying
// firefox also has keyCode=0 for typing, and numeric for everything else
// IE has numeric for typing, 0 for most other things
if( !IE && e.keyCode != 0 ) { return true; }
if( item.value.length >= maxlength ) { if(IE){e.keyCode = 0;} return false; }
}
|