我有一個圖表,一個日期選擇器(日曆)和幾個按鈕的PHP頁面。打印一個URL的內容 - javascript
我想添加另一個按鈕「打印圖表」,它只在本地打印機上打印圖表&而不是整個頁面 。
我試圖通過具有另一腳本(僅輸出圖)和使用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
}
我試過上面的代碼 - 它不工作。打印一張空白頁。
有沒有辦法打印目標網址?如果是,是否可以打印而不必打開新窗口?
感謝您的時間
適合打印的頁面已成爲過去。使用打印樣式表。 – 2009-07-07 21:23:54
如果這是太多的工作,試試這個:W.onload = function(){print(); } – 2009-07-07 21:24:45