如何更改窗口内容的大小?

时间:2021-01-04 09:09:49

I'm maintaining an existing website and I have a document that needs to be printed .

我正在维护一个现有的网站,我有一份需要打印的文件。

I have made some updates to correct some things on the document but the document is made to be printed from a different window. I was wondering both how to make sure the inner html fits inside a browser window and prints inside an 8 1/2 X 11 sheet of paper. Right now it bleeds off the paper and when printed stretches off of the paper worse.

我已经做了一些更新来纠正文档上的一些内容,但是文档是从不同的窗口打印出来的。我想知道如何确保内部html适合浏览器窗口并在8 1/2 X 11张纸内打印。现在它会从纸张上流下来,当打印出纸张时,纸张会变得更糟。

The inner html is just an 870px wide html table yet even reducing the width to 800px does not change how it displays in the window or prints. The printable version is a popup done by injecting a javscript click event by changing a label's .text() property to

内部html只是一个870px宽的html表,但即使将宽度减小到800px也不会改变它在窗口或打印中的显示方式。可打印版本是通过将标签的.text()属性更改为注入javscript click事件来完成的弹出窗口

JS

JS

function printClick() {  
    var w = window.open();  
    var html = $("#prntrForm").html(); 
    html.style.width = '92%';   
    $(w.document.body).html(html); 
}

$(function() {
    $("a#print").click(printClick); 
});  

HTML

HTML

<a href="#"id="print">Printer Form</a>

Anyway I really just need to know how to size the width of the contents of the new window, making the new window have a print function would also be nice but isn't necessary. The similar questions I found seem to point to changing the css but I haven't added a css.

无论如何我真的只需要知道如何调整新窗口内容的宽度,使新窗口具有打印功能也不错,但不是必需的。我发现的类似问题似乎指向更改css但我没有添加css。

1 个解决方案

#1


1  

  • To print the window (bring up the print dialog): w.print()
  • 要打印窗口(调出打印对话框):w.print()
  • To size the window: var w = window.open('', '', 'width=300,height=400');
  • 要调整窗口大小:var w = window.open('','','width = 300,height = 400');

Updated code

更新的代码

function printClick() {  
    var w = window.open('', 'printform', 'width=300,height=400');  
    var html = $("#prntrForm").html(); 
    $(w.document.body).html(html); 
    w.print();
}

#1


1  

  • To print the window (bring up the print dialog): w.print()
  • 要打印窗口(调出打印对话框):w.print()
  • To size the window: var w = window.open('', '', 'width=300,height=400');
  • 要调整窗口大小:var w = window.open('','','width = 300,height = 400');

Updated code

更新的代码

function printClick() {  
    var w = window.open('', 'printform', 'width=300,height=400');  
    var html = $("#prntrForm").html(); 
    $(w.document.body).html(html); 
    w.print();
}