views:

35

answers:

2

Hi All,

I have an asp page having an iframe. I need to set automatic height to iframe. I found an article on http://stackoverflow.com/questions/91721/iframe-sizing but it could not solve my problem. My iframe is

<iframe id="content" src=http://www.bc.com.au/news_manager/templates/?a=&lt;%=request.QueryString("a")%&gt;&amp;z=&lt;%=request.QueryString("z")%&gt; width="908px" height="1000px" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" style="margin-left:auto; margin-right:auto;" ></iframe>

and code on asp page is:

<script type="text/javascript">
   window.onresize=resizeContentFrame;
            resizeContentFrame();

function resizeContentFrame(){
    setFrameHeight(documenent.getElementById('content'));
}

function setFrameHeight(f){
    if(isDefined(f)){
    alert('executing');
        var h=document.documentElement.scrollHeight;
        h-=(HEADER_HEIGHT+CONTENT_PADDING+5);
        f.style.height=h+'px';
    }
}
</script>

In case i dont give a fixed height in iframe it simply cuts the iframe content.

what wrong i am doing while the above script is marked as answer ??

Help...

A: 

Could'nt you just use html-attribute "height" and set it to eg "90%"? Or are the layouts more complicated? In this case you can use a css-attribute and dynamically change this with jQuery.

Olaf Watteroth
Thanks Olaf. But situation is a little bit complicated. I dont know when height will be on peak or whatever. so i need a reliable solution.
Anil
A: 
    var h=document.documentElement.scrollHeight;

That's the height of the document, not the height of the window. You probably want clientHeight not scrollHeight. Also ensure that you are using a Standards Mode <!DOCTYPE, otherwise you get Quirks Mode where you have to look at document.body instead. (And many other undesirable properties.)

In browsers other than IE6-7, you can do this without script. See this question.

?a=<%=request.QueryString("a")%>

HTML-injection. A query like ?a=><script>alert(document.cookie)</script> can inject script content into your page, giving you potential XSS security holes. In any case, you should also be URL-encoding any query parameters you're about to insert into a URL:

url= "http://www.bc.com.au/news_manager/templates/?a="&amp;Server.UrlEncode(Request.QueryString("a"))&amp;"&amp;z="&amp;Server.UrlEncode(Request.QueryString("z"))

<iframe id="content" src="<%= Server.HtmlEncode(url) %>">
bobince