Search results for 'IE'. 2 post(s) found.

  1. 2009/08/28 To get web browser capability
  2. 2008/05/03 IFRAME Auto Resize in IE, FireFox by Javascript (13)
2009/08/28 08:14

To get web browser capability


Now a days, there are four major web browsers: Microsoft Internet Explorer, Mozilla Firefox, Safari, and Opera. But they have the different features not compatible with other browsers. So programmers should pay attention when implement javascript application.

Here's the javascript based Browser Capability check application. This will be very helpful if you are trying to develop global services.
<script type="text/javascript">
// <![CDATA[
var modern = Boolean((( !!document.all === true && !!!document.getElementById ) ? 0 : 1 ));
var xCapabilitIEs = ( function( e ) {
var e = (( e ) ? eval( e ) : window.event );
var xTable = 0;
var count = 1;
var xElem = null;
var xCell = null;
var xDivID = "showCapabilitIEs";
var xDiv = (( modern ) ? document.getElementsByTagName( "div" )[ xDivID ] : document.all.tags( "div" )[ xDivID ] );

tableX = (( modern ) ? xDiv.getElementsByTagName( "table" ) : xDiv.all.tags("table").item( 0 ));
(( tableX[ 0 ] ) ? xDiv.removeChild( tableX[ 0 ] ) : tableX );
delete tableX;

if ( "createElement" in document )
{
  xCell = ( function( row, text )
            {
              var xCel = row.insertCell( -1 );
              return xCel.appendChild( document.createTextNode( text ));
            } );
  xElem = ( function( element )
            {
              return document.createElement( element );
            } );
  xTable = xElem( "table" );

  var xTHead = xTable.createTHead();
  var xRow = xTHead.insertRow( -1 );
  var xLabel = [ "#", "Property", "Value", "Type" ];
  var xLen = xLabel.length;
  for ( i = 0; i < xLen; i++ )
  {
    xCell( xRow, xLabel[ i ] );
  }
  delete i;

  var xTBody = xElem( "tbody" );
  xTable.appendChild( xTBody );
  for ( prop in e )
  {
    xRow = xTBody.insertRow( -1 );
    xCell( xRow, count );
    xCell( xRow, prop );
    xCell( xRow, e[ prop ] );
    xCell( xRow, typeof( e[ prop ] ));
    xRow.lastChild.style.textAlign = "center";
    ++count;
  }
  delete prop;

  xDiv.appendChild( xTable );
  return;
}

alert( "Your browser is not capable of handling this type of script! You'll need to wait for my next version.\n- essential", "http://www.strcpy.com" );
return false;
} );

window.onload = function( event )
{
  var xSel = (( modern ) ? document.getElementById( "browser" ) : document.all.browser );
  xSel.onchange = ( function( event )
  {
    xCapabilitIEs( this.value );
  } );
  xCapabilitIEs( event );
}
// ]]>
</script>

<body>

<div id="content">
<div id="main">
<div class="tube" style="border-bottom : none; clear: both;">
<select id="browser" name="browser" size="1">
<option value="event" selected="selected">- EVENT Objects -</option>
<option value="window">- WINDOW Objects -</option>
<option value="document">- DOCUMENT Objects -</option>
<option value="navigator">- NAVIGATOR Objects -</option></select>
</div>
<div class="tube" id="showCapabilitIEs"></div>
</div>
</div>

</body>

Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2008/05/03 08:39

IFRAME Auto Resize in IE, FireFox by Javascript


Here's the simple iframe auto-resize example working on IE, and FireFox.

<iframe id='ifrm'
                frameborder=0
                width=100%
                height=450
                scrolling=no
                src='http://kurapa.com'
></iframe>

<script language='javascript'>

function getDocHeight(doc)
{
  var docHt = 0, sh, oh;
  if (doc.height)
  {
    docHt = doc.height;
  }
  else if (doc.body)
  {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}
function getReSize()
{
  var iframeWin = window.frames['ifrm'];
  var iframeEl = window.document.getElementById? window.document.getElementById('ifrm'): document.all? document.all['ifrm']: null;
  if ( iframeEl && iframeWin )
  {
    var docHt = getDocHeight(iframeWin.document);
    if (docHt != iframeEl.style.height) iframeEl.style.height = docHt + 'px';
  }
  else
  { // FireFox
    var docHt = window.document.getElementById('ifrm').contentDocument.height;
    window.document.getElementById('ifrm').style.height = docHt + 'px';
  }
}
function getRetry()
{
    getReSize();
    setTimeout('getRetry()',500);
}
getRetry();
</script>

Trackback 0 Comment 13

Trackback : Cannot send a trackbact to this post.