Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic iFrame Resize won't work in Safari?

Status
Not open for further replies.

Twinster

Programmer
Aug 18, 2008
12
SE
Hey!
Well, I have now resolved my previous matter. However, I have an iFrame that dynamically re-size to the content being loaded in to it.

The script works fine when content is added and the iFrame needs to get higher. However, when loading content that is smaller then the previous content the iFrame just won't size down in Safari. In all the other browsers it works fine.

Does anyone have a solution for this?

Best Regards,
R. Darell
 
I suggest you include a link to your current code/page, or that you create a (simple) test page that demonstrates this.

Also, what version of Safari (2 or 3) and what operating system (MacOSX or Windows) are you experiencing this with?

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thanks Jeff!

Ok, this error occurs in the latest Safari version, and OS is both Windows and OSX.

I can't reveal the project yet as it is due to customers request. However, I can maybe try to illustrate it underneath somehow.


Normal State:

iFrame 01 iFrame 02
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXCONTENTXXXX|XXCONTENTXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|


New content in iFrame 01 and back to lesser content in iFrame 01 makes the iFrames look like this in Safari. It doesn't go back to a size fitting the content.

iFrame 01 iFrame 02
iFrame 01 iFrame 02
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXCONTENTXXXX|XXCONTENTXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|XXXXXXXXXXXXXX|XXXXXXXXXXX|
|HHHHHHHHHHHHHH|
|HHHHHHHHHHHHHH|
|HHHHHHHHHHHHHH|
|HHHHHHHHHHHHHH|
|HHHHHHHHHHHHHH|
|HHHHHHHHHHHHHH|

X = Content, H = Blank


I hope this helps. I am using the "onload" expression to trigger the auto-size script.

Anyone have any idea how to solve this issue in Safari. It works fine in IE and FF but however not in Safari.

Best,
Richard
 
Wow, I really in my honest belief thought I had included it in my top thread comment. But I hadn't. LOL

Sooo sorry! Here is the code I am using to autosize the iFrames.

<script language="JavaScript">
<!--
function autoResize(id){
var newheight;
var newwidth;

if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
}

document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}
//-->
</script>


Hope this helps. Really need a solution for this...

Thanks in advance!
Richard
 
Ignoring your problem for a moment, how about reworking that function to be a little neater?
Code:
...
function autoResize(id) {
    if (element = document.getElementById(id)) {
        var mynode = element.contentWindow.document.body;
        element.height= mynode.scrollHeight + "px";
        element.width= mynode.scrollWidth + "px";
    }
}
...
It won't solve your Safari problem, though [smile] Still looking at that.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Hmm - after knocking up a test harness to resize iframes using several methods, it looks like this could be a Safari issue, as I can never get the frames to shrink, either!

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
YES!!!
Works like a charm! Thanks Dan!
Amazingly easy solution! Awesome!

/Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top