PDA

View Full Version : Iframe SSI script II help, please.



katemarie
08-27-2006, 02:32 AM
1) Script Title: Iframe SSI script II (revised version)

2) Script URL (on DD): Original script: http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm

Revised script URL: http://www.dynamicdrive.com/forums/showthread.php?t=5060&page=2 (in post 17)

3) Describe problem: Hi, I'm creating a website on a Mac and I use safari. When I click a link (i.e. main page to "ADS") to open new content in the iframe, the frame adjusts correctly to be larger. But when I click to another page (i.e. "ADS" to "X") with less content, the frame size does not get smaller to fit, it gets bigger. Any help would be greatly appreciated, thanks! Here's my website: http://www.freewebs.com/styliciousblog/index.htm

jscheuer1
08-27-2006, 04:51 AM
Neither the original nor the update that you are using is rated for Safari, but there might be a way to get it to work. First of all though, you have used incorrect syntax in targeting the iframe with your links. This may have nothing to do with the problem but should be taken care of first, just to see. For example, you have:


<a href="welcome.htm" target="myframe">X</a>

The target="myframe" means that the page should open in a window or frame named myframe. However, you have no such named frame. You have one with the id of myframe but, that's different. So, just to eliminate this as a possible problem and to make your page work in a wider number of browsers (IE and FF both open a new window), give the iframe a name as well as an id, they can be the same:


<iframe name="myframe" id="myframe" onload="sizeFrame(this)" src="welcome.htm" scrolling="no" width="100%" height="300" marginwidth="0" marginheight="0" frameborder="yes" align="center" vspace="0" hspace="0" style="border:1px #FF99CC solid; overflow:hidden;"></iframe>

See how that goes. If that doesn't take care of it, see if the onload event is firing or not by adding an alert to this function:


function sizeFrame(frameObj){
alert('fired');
if ((frameObj.contentDocument && (frameObj.contentDocument.body.offsetHeight||frameObj.contentDocument.documentElement.offsetHeight))||frameObj.Document && frameObj.Document.body.scrollHeight){
if (window.opera)
setClicks(frameObj)
var contentHeight=window.opera? frameObj.contentDocument.documentElement.offsetHeight : frameObj.contentDocument? frameObj.contentDocument.body.offsetHeight+13 : frameObj.Document.body.scrollHeight+4
var contentWidth=window.opera? collectWidth(frameObj.contentDocument) : frameObj.contentDocument? frameObj.contentDocument.documentElement.offsetWidth : frameObj.Document.body.scrollWidth
var frameWidth=frameObj.offsetWidth
if (window.opera&&frameWidth>=contentWidth)
frameObj.contentDocument.body.style.overflow='hidden'
frameObj.style.overflow='visible'
frameObj.height = frameWidth<contentWidth? contentHeight+18 : contentHeight+3;
}
}

If it will show the alert each time a new page is loaded into the iframe, then at least the script is trying to work and what may be required is to have Safari follow the same path as Opera, in which your page works fine and which has different code in the script to get the height correct than other browsers, this may also be preferred by Safari. More on that later, if needed.

jscheuer1
08-27-2006, 05:04 AM
I was just taking a closer look at the script, and this may also be tried (it is what I was alluding to at the end of my previous post. Make sure you take care of naming the iframe first).

Change this line:


var contentHeight=window.opera? frameObj.contentDocument.documentElement.offsetHeight : frameObj.contentDocument? frameObj.contentDocument.body.offsetHeight+13 : frameObj.Document.body.scrollHeight+4

to:


var contentHeight=frameObj.contentDocument? frameObj.contentDocument.documentElement.offsetHeight : frameObj.Document.body.scrollHeight+4


That may do it, if the first suggestion did not. I don't have access to a Mac for testing so, you will have to be my eyes on this one.

katemarie
08-27-2006, 05:47 PM
I tried all the suggestions but the iframe is still not resizing to become smaller. I guess I'll just live with this until I get a chance to install firefox on my computer. Thanks for your help!

jscheuer1
08-28-2006, 05:48 AM
You gave up pretty quick. Installing FF will not however, make the script work for other users of Safari, of which there are quite a few.