Jquery resize window to fit content

I have a simple popup with an image 300x300px, I set the size of the window 350x350px, but depending on the browser, I get scroll bars or extra free space. Is there any jQuery function that will resize the browser window to fit the content without any scrollbars or spaces, no matter which browser?

Help me!

+5
source share
4 answers

You can do something like this.

function windowResize() {
   var contentWidth = document.getElementById("YourImageOrContent").offsetWidth;
   var contentHeight = document.getElementById("YourImageOrContent").offsetHeight;
   window.resizeTo(contentWidth,contentHeight);
}

You may need to add 20 pixels or so to the values ​​... But I still keep my original answer: -D

+6
source

, CSS-/, .

:

* {
  padding: 0;
  margin: 0;
  border: 0;
  outline: 0;
}

CSS reset CSS, : -)

, , .

0

( , ), - :

<SCRIPT LANGUAGE="javascript">
<!--
window.open ('image.jpg', 'newwindow', 'height=350,width=350, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no');
-->
</SCRIPT>

scrollbars=no

0

, , , resizeTo . , , "location = no", .

, ( jQuery, , , , , , ):

window.resizeTo(422, $('#my-id').height() + (window.outerHeight - window.innerHeight));

I tested this on Safari, Firefox and Chrome, and it seems to work for everyone (they don't have a Windows installation, so I can't comment on IE).

0
source

All Articles