【发布时间】:2010-11-08 20:13:09
【问题描述】:
我有一个 php 页面,它有一个图表、一个日期选择器(日历)和几个按钮。
我想添加另一个按钮“打印图表”,它只打印图表而不是整个页面 ,在本地打印机中。
我正在尝试通过使用另一个脚本(仅输出图表)并使用 javascript 函数“window.print”来做到这一点
html
<input type="button" onClick="printChart()" value="Print Chart">
javascript
function printChart(){
var myParameters = window.location.search;// Get the parameters from the current page
var URL = "http://my_server/my_folder/my_script_that_outputs_only_my_chart.php"+myParameters;
var W = window.open(URL);
W.window.print(); // Is this the right syntax ? This prints a blank page and not the above URL
}
我尝试了上面的代码 - 它不起作用。打印一个空白页。
有没有办法打印目标网址?如果是,是否可以在不打开新窗口的情况下打印?
感谢您的宝贵时间
【问题讨论】:
-
打印友好页面已成为过去。使用打印样式表。
-
如果工作量太大,试试这个: W.onload = function() { print(); }
标签: javascript url printing