PDA

View Full Version : Resize Iframe Script and Opera



Samus Aran
11-25-2007, 10:36 PM
1) Script Title: Resize Iframe Script John Davenport Scheuer

2) Script URL (on DD): http://www.dynamicdrive.com/forums/showthread.php?t=9139

3) Describe problem: Hi, I am experiencing some issues with this script when I try it on Opera, on IE all works fine.

Note: You must use Opera for the problems to appear.

Here is what is happening:
- If the page does not need a scrollbar, all goes fine.
- If the page needs a scrollbar it will appear but all the other pages will have that same scrollbar.
- If the page needs a longer scrollbar it will work fine, whatever page was loaded first, it will resize a smaller scrollbar just fine.
- If the page needs a shorter scrollbar and I loaded a page with a larger one, it will not resize unless I refresh the page.

Thanks for the help! and I can provide the source of those pages without a problem, simply ask.

Samus Aran
11-25-2007, 10:43 PM
The source of the rzPIframe.js file is:

/* Resize Iframe Script John Davenport Scheuer
As first seen in http://www.dynamicdrive.com/forums
User Name: jscheuer1
This Credit Must Remain for Legal Use
*/

function resizeParentIframe(){
var pad=window.opera? 0 : document.all? 4 : 20;
function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function collectWidth(){
var wVal=0
var objs=document.getElementsByTagName('*')
for (var i_tem = 0; i_tem < objs.length; i_tem++){
wVal=Math.max(objs[i_tem].offsetWidth, wVal)
}
return wVal;
}
parent.document.getElementsByName(window.name)[0].style.height=''
var resizeHeight=document.all? iecompattest().scrollHeight : iecompattest().offsetHeight;
var resizeWidth=window.opera? collectWidth() : iecompattest().scrollWidth;
resizeHeight+=parent.document.getElementsByName(window.name)[0].offsetWidth<resizeWidth? 18 : 0;
parent.document.getElementsByName(window.name)[0].style.height=resizeHeight + pad + 'px'
}

if ( document.getElementsByName && window.name && location.href!==top.location.href && parent.document.getElementsByName(window.name)[0].tagName.toLowerCase()=='iframe' ) {
if ( typeof window.addEventListener != "undefined" ) {
window.addEventListener( "load", resizeParentIframe, false );
parent.window.addEventListener( "resize", resizeParentIframe, false );
}
else if ( typeof window.attachEvent != "undefined" ) {
window.attachEvent( "onload", resizeParentIframe );
parent.window.attachEvent( "onresize", resizeParentIframe );
}
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
resizeParentIframe();
};
}
else
window.onload = resizeParentIframe;

if ( parent.window.onresize != null ) {
var oldOnresize = parent.window.onresize;
parent.window.onresize = function ( e ) {
oldOnresize( e );
resizeParentIframe();
};
}
else
parent.window.onresize = resizeParentIframe;
}
}

jscheuer1
11-26-2007, 07:34 AM
As far as I'm concerned, and I wrote the mod you are referring to, this entire concept is flawed. The iframe tag has already been deprecated. Any implementation of iframe suffers therefore from a lack of standards. This doesn't mean that iframe cannot be used for anything, just that it is tricky, and unlikely to be very 'future proof'. From experience, I can tell you that resizing an iframe in any browser is even trickier, dependant upon the markup and style of both the top and external pages. My demo page of the mod (http://home.comcast.net/~jscheuer1/side/iframe_ssi_III_demo.htm) works, or worked in Opera when I made it. Other than that, you folks are on your own, sorry.

For many but not all things that one would want to use resizable iframe for, Ajax importation to a division is a better choice.

Scripting between iframes' top and contained pages (as in resizing to content), and importing content via Ajax both require that both pages are on the same domain.