views:

176

answers:

4

Is it possible to get a window popup with always 400px wide, but dynamic height depending on the content in the popup window?

I have seen this but not sure how to apply it to popup windows

http://stackoverflow.com/questions/819416/adjust-width-height-of-iframe-to-fit-with-content-in-it

A: 

If you specify overflow: auto and do not specify a height on an element, that element should grow in height dynamically.

jrista
I don't think this applies to windows
larson4
it doesn't work :( but thanks anyway
oy, my bad...thought it was a dhtml popup.
jrista
+1  A: 

The quickest solution would be to know the height of the window prior to opening it. If you know that then you can pass that as a parameter to the function that opens the popup window thus making the popup the correct height.

Avitus
Thanks, but what I need to know is how you find out the height
+2  A: 

Well, since you're relying on JavaScript to popup, you could do this... You've tagged jQuery, so here is a start... Place this in the popup.

$(document).ready(function() {

var popupHeight = parseInt($('#elementThatWillGetTaller').css('height')); // parseInt if we get a '200px'

// code to set window height - I know it can be done because I've seen osCommerce do it
});
alex
This is good, I can then use window.resizeBy()But it doesn't work in IE :(Do you know a workaround for IE?
A: 

Solved

$(document).ready(function() {

  // For IE
  var h = $('#page').outerHeight();
  var newH = h + 20;
  window.resizeBy(0, newH - $(window).height());

  // Only works in Firefox/Safari
  $('img').load(function() {
    var h = $('#page').outerHeight();
    var newH = h + 20;
    window.resizeBy(0, newH - $(window).height());
  });
});