Wednesday, October 10, 2007

How to do Iframe auto resize according to aspx page contain

How to do Iframe auto resize according to aspx page contain
Supose you have one Iframe "IFrmRightMenu" and inside you are setting target for different aspx page, In this case the content of aspx page can have different height and width, If you want to set Iframe size according to aspx page contain height and width then use below function in onload attribute of iframe.
Source code
<script language="javascript">
function autoIFrameResize(id)
   var newheight;
   var the_width=572; //Fixed width      
   if(navigator.appName == "Microsoft Internet Explorer")
{            newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
      if (newheight == 0)
           newheight =584; //Fixed height           
newheight = document.getElementById(id).contentDocument.height;
document.getElementById(id).height= (newheight + 16) + "px";
window.parent.document.getElementById("IFrmRightMenu").style.height= (newheight + 16) + "px";
How to use
<iframe frameborder="no" width="100%" height="100%" onload="autoResize('iframe1');" scrolling ="no" style="visibility:hidden;" id=" iframe1"></iframe>
How to redirect to Parent page from Child page (IFrame)
Let say you have one aspx page with two iframe (LeftIframe and RightIframe in one aspx page), now if you click any button in "RightIframe" and you want to redirect some error page or your want to redirect in home page then you can't simply write Reponse.Redirect ("error.aspx") or Reponse.Redirect ("Home.aspx"), this will display the page in "RightIframe" only.
Use below line of code to redirect page to Home.aspx or Error.aspx
Response.Write("<script>'Error.aspx','_parent');</script>") OR

Check out the hottest 2008 models today at Yahoo! Autos.


Santoo said...

Nice Work Ritesh. It helped me alot.

daspeac said...

I have heard about another way of outlook password recover. Besides, you can visit my blogs at: or where I’m trying to share my experience with regard to data corruption issues.