javascript window.open 根据动态内容自动调整高度和宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12322716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.open auto resize height and width according to dynamic content
提问by deidara song
I'm passing the div value to a window.open popup that should resize height according to content, however when i used auto it just opens a new window. I tried this code but wouldn't work
我将 div 值传递给应该根据内容调整高度的 window.open 弹出窗口,但是当我使用 auto 时,它只会打开一个新窗口。我试过这个代码但不起作用
function openPopup() {
var divText = document.getElementById("pass").outerHTML;
var myWindow = window.open('', '', 'width=500,height=auto');
var doc = myWindow.document;
doc.open();
doc.write(divText);
doc.close();
}
回答by Rikki
I strongly recommend you to use JQuery window, because when you're using window.open, PopupBlocker will cause problems for you. Also window in this way has so limitations, but in JQuery window you can show dynamic content and it works like a charm.
我强烈建议您使用 JQuery 窗口,因为当您使用 window.open 时,PopupBlocker 会给您带来问题。这种方式的窗口也有很多限制,但在 JQuery 窗口中,您可以显示动态内容,而且它的工作原理很吸引人。
By the way, if you have to do this way, "height" property of window does not have "auto" value. So you should handle "onload" event in the page opening in popup window and calculate everything and resize the window at the time window is loaded.
顺便说一句,如果你必须这样做,窗口的“高度”属性没有“自动”值。因此,您应该在弹出窗口中打开的页面中处理“onload”事件并计算所有内容并在加载窗口时调整窗口大小。
Cheers
干杯