Solved

Resize Iframe

Posted on 2006-07-20
6
924 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

734 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