Solved

Resize Iframe

Posted on 2006-07-20
6
930 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 29

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
Suggested Courses

630 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