【发布时间】:2013-10-07 06:48:24
【问题描述】:
我想打开一个页面,但不是查看它,而是要求用户打印。
这与Content Disposition HTTP 标头的功能非常相似。
当设置为attachment 时,它会询问用户将文件保存在哪里(而不是在浏览器中显示)。
我有权限为用户打开页面,所以我可以use javascript:
var doc = open(url); //open the link for them instead of using an anchor href
doc.print(); //ask them to print it, this is a blocking call until the user is done
doc.close(); //immediately close the window so the user isn't interrupted
但我真的希望有一些我可以使用的服务器端标志,有这样的东西吗?
打开的页面不一定是 HTML 文档,因此在其中使用window.print();window.close(); 并非在所有情况下都有效。
【问题讨论】:
-
HTTP 不是 HTML,但您的回答似乎表明 HTTP 也没有好东西
-
另外,我认为这个问题是指打印当前所在的页面。未链接到 将出现打印对话框的文档。
标签: javascript html http printing http-headers