javascript 如何在保存打印页面时为文件创建自定义文件名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10189225/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 08:58:35 来源:igfitidea点击:
How to create a custom file name for a file while saving the print page?
提问by Rooney
Here i am printing a page through window.print() event and before printing i need to save this page for that i need to hardcore a file name in this event.
在这里,我通过 window.print() 事件打印页面,在打印之前我需要保存此页面,因为我需要在此事件中硬核一个文件名。
<a href="_javascript:window.print()">
<img class="noPrint" src="Images/Print_icon.png" border="0"></a>
Any suggestion?
有什么建议吗?
回答by Tim Schmelter
You can change the title via document.title
:
您可以通过document.title
以下方式更改标题:
<a href="someRealUrl" onclick="document.title='My new title'; window.print(); return false;"><img class="noPrint" src="Images/Print_icon.png" border="0"></a>
回答by bala3569
onClick="document.title = "My new title";window.print();"