Solved

Resize Iframe

Posted on 2006-07-20
6
913 Views
Last Modified: 2009-07-29
I want to resize the iframe depending on the the size of the document loaded
into to the iframe so that i can use IE to scroll
0
Comment
Question by:anand
6 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 125 total points
ID: 17151960
Like this:

<IFRAME name="myiframe" onload="this.style.height=parseInt(window.frames.myiframe.document.body.scrollHeight)+50;" style="OVERFLOW: auto; WIDTH: 100%;height:100%;" src="joke.htm" frameBorder="1"></IFRAME>


0
 

Author Comment

by:anand
ID: 17152385
Thanks for u r reply,

i tried the code which u have mentioned above,
but, i dont want to use the iframe's scrolling bar instead i want to scroll using the IE 's scroll bar,how can i do that


thank u
anand


0
 
LVL 28

Assisted Solution

by:Pravin Asar
Pravin Asar earned 125 total points
ID: 17153085
Here is a another approach (uses iframe as buffer with auto-size of div tag).

To do this, you could have hidden iframe, and send the contents to div.
Here is an example. Only thing is the iframe page should be from your own domain.
For security purpose you can not read the external domain pages (other than yours).


 

<html>
<head>
<title>Using an Iframe as a Buffer</title>
<style type="text/css">
</style>
<script type="text/javascript">
function loadExternal(url) {
  if (window.frames['buffer'] ) {
    window.frames['buffer'].location = url;
    var lyr = document.getElementById? document.getElementById('MainDisplay'): document.all? document.all['MainDisplay']: null;
    if ( lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = '<img src="/images/loading.gif" alt="">';      
    }
    return false;
  }
  return true; // other browsers follow link
}

// called when documents loaded into iframe (from their body's onload attribute)
function displayExternal() {
  var lyr = document.getElementById? document.getElementById('MainDisplay'): document.all? document.all['MainDisplay']: null;
    if ( window.frames['buffer'] && lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = window.frames['buffer'].document.body.innerHTML;
    }
}
</script>
</head>
<body>
<h1>Welcome!</h1>
<p>This is an example, how we can have dynamically sized div (using IFRAME as a buffer).</p>
<p>NOTE: All page should be from current domain! to obtain the page properties.</p>
<style type="text/css">
TD { width: 200px;}
</style>
<div id="lnks">
  <table>
  <tr>
       <td>
       <a href="page1.htm" onclick="return loadExternal(this.href)">Page1</a>
     </td>
       <td>
            <a href="page2.htm" onclick="return loadExternal(this.href)">Page2</a>
     </td>
       <td>
            <a href="page3.htm" onclick="return loadExternal(this.href)">page3</a>
     </td>
  </tr>
  </table>
</div>


<div id="MainDisplay" style="position:absolute; top: 100px; width: 600px; height:auto; ">HELLO</div>
<iframe id="buffer" style="display:none; " name="buffer" src="page1.htm" onload="displayExternal();">Sorry, your browser does not support iframes.</iframe>

</body>
</html>
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question