简体   繁体   English

Javascript打印功能 - 文件名

[英]Javascript Print function - file name

I am using the window.print() function in javaScript to print a page which is executed from a button onClick. 我在javaScript中使用window.print()函数来打印一个从onClick按钮执行的页面。

<input type="submit" value="Print" class="register-button" onClick="window.print()"/>

In the popup the default filename is the name of the website found it the tags in the header. 在弹出窗口中,默认文件名是网站的名称,它在标题中找到标记。

Is there anyway I can set a parameter in the function so the default save filename is what ever I want it to be? 无论如何我可以在函数中设置一个参数,所以默认的保存文件名是我想要的吗?

Cheers. 干杯。

onClick="document.title = 'My new title';window.print();"

You can try it here: 你可以在这里试试:

  <html> <head> <title>My title</title> </head> <body> <button onClick="document.title = 'My new title';window.print();">Try it</button> <p id="demo"></p> </body> </html> 

According to MDC, window.print() has no parameters to control anything. 根据MDC, window.print()没有控制任何东西的参数。

https://developer.mozilla.org/en/DOM/window.print https://developer.mozilla.org/en/DOM/window.print

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM