Automatically resize windows?
Is it possible to make a pop-up window automa开发者_如何学Gotically resize to fit all the text and images contained in a page?
This will work in chrome. You might need to tweak it for IE. It's all plain javascript, except for the $().ready, which you could replace with whatever load handler you want.
It assumes you place the contents of your popup in a div with display set to inline-block. You may have to add a little bit more offset if you have padding or margins.
<div id="content" style="display: inline-block">...
$().ready(function() {
setTimeout(function() {
var heightOffset = window.outerHeight - window.innerHeight;
var widthOffset = window.outerWidth - window.innerWidth;
var height = document.getElementById("content").clientHeight + heightOffset;
var width = document.getElementById("content").clientWidth + widthOffset;
window.resizeTo(width, height);
}, 100);
});
using jQuery:
window.resizeTo($(document.body).width(), $(document.body).height());
But this will most likely not work in most browsers (does not work in chrome for example) as it is mostly misused. More info on http://www.w3schools.com/jsref/met_win_resizeto.asp
精彩评论