aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Dynamic change the iframe height Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Dynamic change the iframe height" Watch "Dynamic change the iframe height" New topic
Author

Dynamic change the iframe height

jack zhangyunjie
Greenhorn

Joined: Jan 04, 2008
Posts: 7
Now i have a iframe in the div.but the message of the iframe is dynamic.
i want to know how make the height of the div to suit the height of the iframe.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
<div>
<iframe
src ="/message.jsp"
width="100%"
height="<%= frame.getHeight() %>">
</iframe>
</div>
[ May 02, 2008: Message edited by: James Clark ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

Originally posted by James Clark:
height="<%= frame.getHeight() %>">

That's not going to work. The JSP on the server has no knowledge of the iframe's size, or even of the iframe itself.

To the OP: <div> elements will generally size themselves as appropriate to their content. Why do you feel the need to set it explicitly?
[ May 02, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
height="<%= frame.getHeight() %>">

That's not going to work. The JSP on the server has no knowledge of the iframe's size, or even of the iframe itself.


I'm not sure why you think that JSP page does not know about the IFRAME element and it's attributes. To dynamically set the height of the IFRAME element you would use the code above. What is above is only an example. It demonstrates the key concept of attribute value assignment via JSP scriplet. This is how developers can assign dynamic values to the HTML attributes within the page.

Remember, JSP pages are converted to serlvets and then produce the HTML that is sent to the browser via HttpResponse object. The IFRAME element is coming from the server. The JSP and the converted servlet certainly have knowledge about the HTML they produce/send to browser.
[ May 02, 2008: Message edited by: James Clark ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

Originally posted by James Clark:
The IFRAME element is coming from the server. The JSP, servlet certainly have knowledge about the HTML they produce/send to browser.
Not so. To the Servlet and JSP engines the HTML markup is just so much template text. The JSP has no knowledge whatsoever of the elements that the HTML markup will create on the client.

In your example, what is frame? Where is it defined?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

Originally posted by James Clark:
It demonstrates the key concept of attribute value assignment via JSP scriplet. This is how developers can assign dynamic values to the HTML attributes within the page.
While the example does clearly show how a scriptlet expression can be used to embed a dynamic value in the HTML markup, it doesn't address the OP's question of knowing what value to use.

Again, the server knows nothing of the HTML elements that will be rendered by whatever markup it will send to the client.

You can define a frame bean and give it a height property with a fixed value, but that doesn't bear any relationship to the actual iframe that has yet to be created on the client.

P.S. Scriptlet expressions themselves are very passé in JSP 2 where the EL should be preferred.
[ May 02, 2008: Message edited by: Bear Bibeault ]
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
In your example, what is frame? Where is it defined?


Oh well, we would have gotten to that eventually

In my example, frame would be a variable name of an object that contains the size value for the IFRAME. Below is a rough sketch of how this can be implemented.




The HTML elements are coming from the web server and are part of the JSP page.
[ May 02, 2008: Message edited by: James Clark ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

Right, you can assign whatever values you want either by hard-coding them in the markup, or dynamically assigning them via scriptlets/EL. But these values cannot be divined from actual metrics on the UI. They're just numbers you hard-coded on the server rather than the client.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60071
    
  65

Originally posted by James Clark:
The HTML elements are coming from the web server and are part of the JSP page.
Again, not quite. Saying it like makes it sound like the JSP is aware of the HTML elements that will be created. It is not. The JSP merely sends the markup of the HTML to the client for interpretation by the browser.

The text "<iframe>" means no more to the JSP than does "aksjlfdsajkhgf". It's the browser that turns the markup text into elements.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by James Clark:


In my example, frame would be a variable name of an object that contains the size value for the IFRAME.



Can you see how calling your bean "frame" might give a newcomer the wrong impression that the JSP code can somehow interact, directly with the DOM elements running in the browser; especially in your first code example in which the useBean tag is not present?
[ May 02, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Again, not quite. Saying it like makes it sound like the JSP is aware of the HTML elements that will be created. It is not. The JSP merely sends the markup of the HTML to the client for interpretation by the browser.

The text "<iframe>" means no more to the JSP than does "aksjlfdsajkhgf". It's the browser that turns the markup text into elements.


Thank you for clarifying this. I still am kinda rough with my technical writing skills.

Can you see how calling your bean "frame" might give a newcomer the wrong impression that the JSP code can somehow interact, directly with the DOM elements running in the browser; especially in your first code example in which the useBean tag is not present?


Thank you. A newcomer might have gotten the wrong impression.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1973
    
    7

try this link for your dynanmic iframe height


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic change the iframe height
 
Similar Threads
IFRAME height difference between IE and Firefox
Initial Text Content for an IFrame - Firefox issue
change the iframe height dynamically in a jsp page
disable horizontal scrollbar of window is possible?
Iframe space problem