Javascript 打印功能 - 文件名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4467578/
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
Javascript Print function - file name
提问by Samuel Meddows
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.
干杯。
回答by Caner
onClick="document.title = 'My new title';window.print();"
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>
回答by Ming-Tang
According to MDC, window.print()has no parameters to control anything.
根据 MDC,window.print()没有参数可以控制任何东西。

