This article has been dead for over three months
You
/******************************
Developed By DANIuser : essential -
* Created : May 23rd, 2009 -
* Title : Iframe Fixer v1.0 -
* This notice MUST stay intact for use -
* http://www.daniweb.com/forums/member383844.html
******************************/
var $load;
var $tagNames;
var $iframe;
var $script, script;
var $tags;
var $fixed, $auto;
var $fwidth, $fheight
var $iframeId;
////////////////////////////////////////
/////////CONFIGURATION////////
////////////////////////////////////////
/* The $fwidth and $fheight can be referred as ( n-px, n-em, n-%, or auto ) were n is the number value ~
And will only work if the $fixed sized value is set to true. //*/ESSENTIAL
////////////////////////////////////////
////////////////////////////////////////
$iframeId = "iframes" // You may specify your iframe id if you only have 1 iframe element inside your page, otherwise ignore this -
$fwidth = "100%"; // You may specify iframe width if $fixed size is set to true.
$fheight = "1000px"; // You may specify iframe height if $fixed size is set to true;
$fixed = true; // Set to false if you want to auto-fit your iframe elements'.
////////////////////////////////////////
//////DO NOT ALTER THE////////////////LINES BELOW///////////
////////////////////////////////////////
$auto = Boolean();
$auto = (( $fixed ) ? false : true );
if ( !$fixed ) {
$fwidth = null;
$fheight = null;
}
$tagNames = Boolean( document.getElementsByTagName );
$tags = Object.prototype.$tags = function( isTag ) {
if ( $tagNames ) {
return document.getElementsByTagName( isTag );
} else if ( document.all && !document.getElementByI ) {
return document.all.tags( isTag );
} return alert("Unsupported JavaScript Features!\nPlease upgrade your browse.");
};
$iframe = function( ref, $width, $height, iframeId ) {
$function = "\nvar testFunc, iHeight, iWidth;\n";
$function += "var myFrame, iframeId;\n";
$function += "testFunc = function() {\n";
$function += "iframeId = \u0022" + $iframeId + "\u0022\n";
if( $auto ) {
$function += "iHeight = $tags('body')[ 0 ].scrollHeight + ( \u0022px\u0022 );\n";
$function += "iWidth = ( \u0022100%\u0022 );\n";
} else {
$function += "iHeight = ( \"" + (( typeof $height === "number" ) ? Number( $height ) : String( $height )) + "\" );\n";
$function += "iWidth = ( \"" + (( typeof $width === "number" ) ? Number( $width ) : String( $width )) + "\" );\n";
}
$function += "if ( window.top.frames.length <= 1 ) {\n";
$function += "myFrame = window.top.$tags('iframe')[ iframeId ];\n";
$function += "if (( !myFrame.style.height ) || ( !myFrame.style.width )) {\n";
$function += "myFrame.style.height = iHeight;\n";
$function += "myFrame.style.width = iWidth;\n";
$function += "}\n";
$function += "else {\n";
$function += " myFrame.setAttribute( 'style', 'height : ' + iHeight + '; width : ' + iWidth );\n";
$function += "}\n";
$function += "}\n";
$function += "else {\n";
$function += "for ( var x = 0; x < window.top.frames.length; x++ ) {\n";
$function += "myFrame = window.top.$tags(\u0022iframe\u0022);\n"
$function += "if (( !myFrame[ x ].style.height ) || ( !myFrame[ x ].style.width )) {\n"
$function += "myFrame[ x ].style.height = iHeight;\n";
$function += "myFrame[ x ].style.width = iWidth;\n";
$function += "}\n";
$function += "else {\n";
$function += "myFrame[ x ].setAttribute( 'style', 'height : ' + iHeight + '; width : ' + iWidth + ';' );\n";
$function += "}\n";
$function += "}\n}\n};\n";
$function += "$load( testFunc );\n";
script = document.createTextNode( $function );
$script = document.createElement("script");
$script.type = "text/javascript";
$script.appendChild( script );
if ( $tagNames ) {
if ( self.frames.length !== 0 ) {
return false;
} else {
$tags("head")[ ref ].appendChild( $script );
}
} else {
$tags("head")[ ref ].insertAdjacentElement("afterEnd", $script );
}
};
// Based on Simon Willison's addLoadEvent -->
// This is highly needed for multiple load events.
$load = function( myFunc ) {
thisFunc = window.onload;
if ( typeof window.onload !== "function" ) {
window.onload = myFunc;
} else {
window.onload = function() {
if ( thisFunc ) {
thisFunc( );
} myFunc( );
};
}
}; $load( $iframe( 0, $fwidth, $fheight ));