problem with iframe resizing 2

K

khothikhe

Can someone help me here because this is really killing me!

the problem is, i have this javascript code in my aspx page that i want it
to work on almost all browsers, especially opera and safari :

function resize(){
displayFrm = document.getElementById("ifrmDisplay");

innerDoc = (displayFrame.contentDocument) ?displayFrm.contentDocument :
displayFrm.contentWindow.document;

objToResize = (displayFrm.style) ? displayFrm.style : displayFrm;

objToResize.height = innerDoc.body.scrollHeight;
}

the code above gets called every time a new page is loaded inside the iframe
(ifrmDisplay) what its doing is resizing the iframe so it can have the same
size as the page inside it, so i can eliminate the need for vertical
scroller for the iframe, i assumed that it works on opera and IE at the same
time, when i tried it out, it worked on IE but not on opera. after lot of
time in researching how i can get workaround this issue with opera, that is
the best possible solution i have and yet it doesnt work. so i gave up and
asking you if you can help me out here , coz this is jst driving me crazy!

the problem is im not a javascript expert, to be honest i jst started doing
javascripts about two days ago, that is why im in need for help

by the way, here is inner html for the iframe if its any use

<iframe id="ifrmDisplay" style="Z-INDEX: 99; LEFT: 187px; WIDTH: 567px;
POSITION: absolute; TOP: 136px; HEIGHT: 408px" src="" scrolling="no"
onload="resize();">
</iframe>
 
J

Julian Turner

Hello

Some quick thoughts.

You may need to be clearer about what exactly is not working.

Is it that:-

(1) the IFRAME onload event (and resize function) is not firing at
all, or

(2) that the resize function is not working as expected (i.e. the
height is not the desired height)?

1. ONLOAD EVENT

I think (I could be wrong) that Opera does not support the onload
event on the IFRAME element.

It does however I think support the "readyState" property on
documents.

So in Opera, your only way may be to include either:-

(a) Some script within the web page to be loaded in the IFRAME, that
calls the parent method:-

<BODY onload="window.parent.resize('IFRAMEID')">

(b) Monitor the document readyState from the parent using a
setInterval process.

I.e. if (myIFrame.contentWindow.document.readyState=="complete"){resize();}

2. IFRAME not resizing properly

The scrollHeight value may not be reliable.

Browsers may vary as to whether they take into account margins around
HTML and BODY elements. So you may need to experiment a little here.

Also, you need to take into account the borders and margins of the
IFRAME element itself.

3. FURTHER READING

A useful page on IFRAMES is:-

http://www.dyn-web.com/dhtml/iframes/

A similar post on another site:-

http://www.ozoneasylum.com/9671&latestPost=true

Julian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top